Problem: It is the year 2969. 1000 years have passed from the moon landing. Meanwhile, the humanity colonized the Hyperspace™ and lived in harmony.

Until we realized that we were not alone.

Not too far away from the Earth, the massive fleet of aliens' spaceships is preparing to attack the Earth. For the first time in a while, the humanity is in real danger. Crisis and panic are everywhere. The scientists from all around the solar system have met and discussed the possible solutions. However, no progress has been made.

The Earth's last hope is YOU!

Fortunately, the Earth is equipped with very powerful defense systems made by MDCS. There are N aliens' spaceships which form the line. The defense system consists of three types of weapons: 

  * SQL rockets – every SQL rocket can destroy at most one spaceship in the given set.
  * Cognition beams – every Cognition beam has an interval [l,r] and can destroy at most one spaceship in that interval.
  * OMG bazooka – every OMG bazooka has three possible targets, however, each bazooka can destroy either zero or exactly two spaceships. In addition, due to the smart targeting system, the sets of the three possible targets of any two different OMG bazookas are disjoint (that means that every ship is targeted with at most one OMG bazooka). 



Your task is to make a plan of the attack which will destroy the largest possible number of spaceships. Every destroyed spaceship should be destroyed with exactly one weapon.

Input

The first line contains two integers: the number of your weapons N (1≤ N≤ 5000) and the number of spaceships M (1≤ M≤ 5000).

In the next N lines, each line starts with one integer that represents type (either 0, 1 or 2). If the type is 0, then the weapon is SQL rocket, the rest of the line contains strictly positive number K (∑{K} ≤ 100 000) and array k_i (1≤ k_i≤ M) of K integers. If the type is 1, then the weapon is Cognition beam, the rest of the line contains integers l and r (1≤ l≤ r≤ M). If the type is 2 then the weapon is OMG bazooka, the rest of the line contains distinct numbers a, b and c  (1 ≤ a,b,c ≤ M).

Output

The first line should contain the maximum number of destroyed spaceships — X.

In the next X lines, every line should contain two numbers A and B, where A is an index of the weapon and B is an index of the spaceship which was destroyed by the weapon A.

Example

Input

3 5
0 1 4
2 5 4 1
1 1 4


Output

4
2 1
3 2
1 4
2 5

Note

SQL rocket can destroy only 4th spaceship. OMG Bazooka can destroy two of 1st, 4th or 5th spaceship, and Cognition beam can destroy any spaceship from the interval [1,4]. The maximum number of destroyed spaceship is 4, and one possible plan is that SQL rocket should destroy 4th spaceship, OMG bazooka should destroy 1st and 5th spaceship and Cognition beam should destroy 2nd spaceship.

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
uint64_t rnd_data = 0xDEADBEEFDULL;
inline void my_srand(int seed) { rnd_data = ((uint64_t)seed << 16) | 0x330E; }
inline int my_rand() {
  rnd_data = rnd_data * 0x5DEECE66DULL + 0xB;
  return (rnd_data >> 17) & 0x7FFFFFFF;
}
template <typename T>
void my_random_shuffle(T b, T e) {
  for (int i = (1); i <= (int)((int)(e - b) - 1); i++) {
    swap(b[i], b[my_rand() % (i + 1)]);
  }
}
template <class _T>
inline _T sqr(const _T &x) {
  return x * x;
}
template <typename type_t, typename less_t = std::less<type_t>>
inline bool uin(type_t &a, const type_t &b, const less_t &ls = less_t()) {
  return ls(b, a) ? a = b, true : false;
}
template <typename type_t, typename less_t = std::less<type_t>>
inline bool uax(type_t &a, const type_t &b, const less_t &ls = less_t()) {
  return ls(a, b) ? a = b, true : false;
}
const long double PI = 3.1415926535897932384626433832795L;
const long double EPS = 1e-9;
int n, m, k;
int t[5024];
vector<int> b[5024];
int orig[5024];
int num[5024];
bool g[5024][5024];
bool u[5024];
int ans[5024][2];
int pa[5024];
int p1[5024];
int idx[5024];
bool find(int v) {
  u[v] = true;
  for (int i = 0; i < (int)(k); i++) {
    if (g[v][i] && pa[i] == -1) {
      pa[i] = v;
      return true;
    }
  }
  for (int i = 0; i < (int)(k); i++) {
    if (g[v][i] && (pa[i] == -1 || (!u[pa[i]] && find(pa[i])))) {
      pa[i] = v;
      return true;
    }
  }
  return false;
}
int main() {
  scanf("%d%d", &n, &m);
  memset((u), 0, sizeof(u));
  for (int i = 0; i < (int)(n); i++) {
    scanf("%d", &t[i]);
    if (t[i] == 0) {
      int x;
      scanf("%d", &x);
      b[i].resize(x);
      for (int j = 0; j < (int)(x); j++) {
        scanf("%d", &b[i][j]);
        b[i][j]--;
      }
    } else if (t[i] == 1) {
      b[i].resize(2);
      for (int j = 0; j < (int)(2); j++) {
        scanf("%d", &b[i][j]);
        b[i][j]--;
      }
    } else {
      b[i].resize(3);
      for (int j = 0; j < (int)(3); j++) {
        scanf("%d", &b[i][j]);
        b[i][j]--;
        u[b[i][j]] = true;
      }
    }
  }
  k = 0;
  for (int i = 0; i < (int)(m); i++) {
    if (!u[i]) {
      orig[k] = i;
      num[i] = k++;
    }
  }
  int kk = k;
  for (int i = 0; i < (int)(n); i++) {
    if (t[i] != 2) continue;
    for (int j = 0; j < (int)(3); j++) {
      orig[k] = i;
      num[b[i][j]] = k;
    }
    k++;
  }
  memset((g), 0, sizeof(g));
  for (int i = 0; i < (int)(n); i++) {
    if (t[i] == 0) {
      for (int j : b[i]) {
        g[i][num[j]] = true;
      }
    } else if (t[i] == 1) {
      for (int j = (b[i][0]); j <= (int)(b[i][1]); j++) {
        g[i][num[j]] = true;
      }
    }
  }
  memset(pa, 0xff, sizeof(pa));
  memset(p1, 0xff, sizeof(p1));
  for (int i = 0; i < (int)(n); i++) {
    idx[i] = i;
  }
  sort(idx, idx + n, [](int l, int r) {
    bool l1 = t[l] == 1;
    bool r1 = t[r] == 1;
    if (l1 != r1) return l1;
    return b[l][0] > b[r][0];
  });
  for (int i1 = 0; i1 < (int)(n); i1++) {
    int i = idx[i1];
    for (int j = 0; j < (int)(k); j++) {
      if (g[i][j] && pa[j] == -1) {
        pa[j] = i;
        p1[i] = j;
        break;
      }
    }
  }
  memset((u), 0, sizeof(u));
  for (int i1 = 0; i1 < (int)(n); i1++) {
    int i = idx[i1];
    if (p1[i] != -1) continue;
    if (find(i)) memset((u), 0, sizeof(u));
  }
  int cnt = 0;
  for (int i = 0; i < (int)(k); i++) {
    if (pa[i] != -1) {
      if (i < kk) {
        ans[cnt][0] = pa[i];
        ans[cnt][1] = orig[i];
        cnt++;
      } else {
        int v = pa[i];
        int y = -1;
        bool fnd = false;
        if (t[v] == 0) {
          for (int vn : b[v]) {
            if (num[vn] == i) {
              fnd = true;
              y = vn;
              break;
            }
          }
        } else {
          for (int vn = (b[v][0]); vn <= (int)(b[v][1]); vn++) {
            if (num[vn] == i) {
              fnd = true;
              y = vn;
              break;
            }
          }
        }
        assert(fnd);
        ans[cnt][0] = v;
        ans[cnt][1] = y;
        cnt++;
        int bn = orig[i];
        for (int j = 0; j < (int)(3); j++) {
          if (b[bn][j] == y) continue;
          ans[cnt][0] = bn;
          ans[cnt][1] = b[bn][j];
          cnt++;
        }
      }
    } else {
      if (i >= kk) {
        int bn = orig[i];
        for (int j = 0; j < (int)(2); j++) {
          ans[cnt][0] = bn;
          ans[cnt][1] = b[bn][j];
          cnt++;
        }
      }
    }
  }
  printf("%d\n", cnt);
  for (int i = 0; i < (int)(cnt); i++) {
    printf("%d %d\n", ans[i][0] + 1, ans[i][1] + 1);
  }
  return 0;
}