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;
const int maxv = 1e5 + 10, maxe = 1e6 + 10, oo = 1e9, maxn = 5e3 + 10;
int N, ans, n, m, S, T, head[maxv], e_n, to[maxe], cap[maxe], d[maxv],
    nxt[maxe], iter[maxv], typ[maxn], a[maxn][3], bel[maxn];
vector<int> rem[maxn];
void add_edge(int u, int v, int c) {
  to[e_n] = v;
  cap[e_n] = c;
  nxt[e_n] = head[u];
  head[u] = e_n++;
  to[e_n] = u;
  cap[e_n] = 0;
  nxt[e_n] = head[v];
  head[v] = e_n++;
  return;
}
void seg_B(int l = 1, int r = m, int k = 1) {
  if (l == r) {
    N = max(N, k + T);
    add_edge(k + T, l + n, 1);
    return;
  }
  int mid = l + r >> 1, u = k + T, lc = k << 1, rc = lc | 1;
  add_edge(u, lc + T, oo);
  seg_B(l, mid, lc);
  add_edge(u, rc + T, oo);
  seg_B(mid + 1, r, rc);
  return;
}
void seg_add(int u, int a, int b, int l = 1, int r = m, int k = 1) {
  if (a <= l && r <= b) {
    add_edge(u, k + T, 1);
    return;
  }
  int mid = l + r >> 1;
  if (a <= mid) seg_add(u, a, b, l, mid, k << 1);
  if (b > mid) seg_add(u, a, b, mid + 1, r, (k << 1) | 1);
  return;
}
bool bfs() {
  static int q[maxv], fnt, rar;
  memset(d, -1, sizeof(d[0]) * N);
  fnt = rar = 0;
  q[rar++] = S;
  d[S] = 0;
  while (fnt != rar) {
    int u = q[fnt++];
    for (int i = head[u]; ~i; i = nxt[i])
      if (cap[i] && d[to[i]] == -1) d[q[rar++] = to[i]] = d[u] + 1;
  }
  return d[T] != -1;
}
int dfs(int u = S, int f = oo) {
  if (u == T) return f;
  int t = f;
  for (int v, &i = iter[u]; ~i; i = nxt[i])
    if (cap[i] && d[v = to[i]] == d[u] + 1) {
      int F = dfs(v, min(t, cap[i]));
      t -= F;
      cap[i] -= F;
      cap[i ^ 1] += F;
      if (!t) return f;
    }
  return f - t;
}
int main() {
  memset(head, -1, sizeof head);
  scanf("%d%d", &n, &m);
  S = 0, T = n + m + 1;
  for (int i = 1; i <= m; ++i) add_edge(i + n, T, 1);
  seg_B();
  for (int i = 1; i <= n; ++i) {
    scanf("%d", typ + i);
    if (typ[i] == 0) {
      add_edge(S, i, 1);
      int k;
      scanf("%d", &k);
      while (k--) {
        int u;
        scanf("%d", &u);
        add_edge(i, u + n, 1);
      }
    } else if (typ[i] == 1) {
      add_edge(S, i, 1);
      int l, r;
      scanf("%d%d", &l, &r);
      seg_add(i, l, r);
    } else {
      add_edge(S, i, 2);
      for (int j = 0; j < 3; ++j) {
        scanf("%d", a[i] + j);
        add_edge(i, a[i][j] + n, 1);
      }
    }
  }
  ++N;
  while (bfs()) {
    memcpy(iter, head, sizeof(iter[0]) * N);
    for (int f = dfs(); f; f = dfs()) ans += f;
  }
  printf("%d\n", ans);
  for (int i = 1; i <= m; ++i) {
    int u = i + n;
    bool flag = 0;
    for (int j = head[u]; ~j; j = nxt[j]) flag |= (to[j] == T && cap[j] == 0);
    if (flag) {
      for (int j = head[u]; ~j; j = nxt[j])
        if (to[j] <= n && cap[j]) {
          rem[bel[i] = to[j]].push_back(i);
          flag = 0;
          break;
        }
      if (flag) {
        while (u > n) {
          for (int j = head[u]; ~j; j = nxt[j])
            if ((j & 1) && cap[j]) {
              u = to[j];
              --cap[j];
              break;
            }
        }
        rem[bel[i] = u].push_back(i);
      }
    }
  }
  for (int i = 1; i <= n; ++i)
    if (typ[i] == 2 && rem[i].size() == 1) {
      for (int u, j = 0; j < 3; ++j)
        if ((u = a[i][j]) != rem[i][0]) {
          int k = bel[u];
          for (int s = 0; s < rem[k].size(); ++s)
            if (rem[k][s] == u) {
              swap(rem[k][s], rem[k][rem[k].size() - 1]);
              break;
            }
          rem[k].pop_back();
          rem[i].push_back(u);
          break;
        }
    }
  for (int i = 1; i <= n; ++i) {
    for (int x : rem[i]) printf("%d %d\n", i, x);
  }
  return 0;
}