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;
void rd(int &t) {
  t = 0;
  char p = getchar();
  while (p == ' ' || p == '\n') p = getchar();
  do {
    (t *= 10) += p - '0';
    p = getchar();
  } while (p >= '0' && p <= '9');
}
const int N = 500005, M = N << 2, inf = 1 << 30;
int to[M], nxt[M], len[M], inv[M], fir[N], cur[N], idx[N];
int Q[N], lev[N], pos[N], tot[N], n, m, cnt, ecnt, S, T;
bool vis[N];
struct qst {
  int opt, l, r, k, a, b, c;
} q[N];
void ae(int u, int v, int w) {
  to[++ecnt] = v;
  nxt[ecnt] = fir[u];
  len[ecnt] = w;
  inv[ecnt] = ecnt + 1;
  fir[u] = ecnt;
  to[++ecnt] = u;
  nxt[ecnt] = fir[v];
  len[ecnt] = 0;
  inv[ecnt] = ecnt - 1;
  fir[v] = ecnt;
}
struct Seg {
  void build(int rt, int l, int r) {
    if (l == r) {
      idx[rt] = l;
      return;
    }
    idx[rt] = ++cnt;
    int mid = l + r >> 1;
    build(rt << 1, l, mid);
    build(rt << 1 | 1, mid + 1, r);
    ae(idx[rt], idx[rt << 1], inf);
    ae(idx[rt], idx[rt << 1 | 1], inf);
  }
  void link(int rt, int l, int r, int ql, int qr, int id) {
    if (ql <= l && r <= qr) {
      ae(id, idx[rt], 1);
      return;
    }
    int mid = l + r >> 1;
    if (ql <= mid) link(rt << 1, l, mid, ql, qr, id);
    if (qr > mid) link(rt << 1 | 1, mid + 1, r, ql, qr, id);
  }
} seg;
bool make_level() {
  int u, v, w, l, r, i;
  memset(vis, false, sizeof(vis));
  for (i = S; i <= T; ++i) cur[i] = fir[i];
  Q[l = r = 1] = S;
  vis[S] = true;
  while (l <= r) {
    u = Q[l++];
    for (i = fir[u]; i; i = nxt[i]) {
      v = to[i];
      w = len[i];
      if (w && !vis[v]) {
        vis[Q[++r] = v] = true;
        lev[v] = lev[u] + 1;
      }
    }
  }
  return vis[T];
}
int dinic(int u, int lim) {
  if (u == T) return lim;
  int ret = 0, tmp, v, w, i;
  for (i = cur[u]; i; i = nxt[i]) {
    v = to[i];
    w = len[i];
    if (w && lev[v] == lev[u] + 1) {
      tmp = dinic(v, min(w, lim));
      len[i] -= tmp;
      len[inv[i]] += tmp;
      lim -= tmp;
      ret += tmp;
      if (!lim) {
        cur[u] = i;
        return ret;
      }
    }
  }
  cur[u] = 0;
  return ret;
}
void work(int u, int &x, int pre) {
  if (x) return;
  if (u > m && u <= n + m) {
    x = u - m;
    return;
  }
  int i, v, w;
  for (i = fir[u]; i; i = nxt[i]) {
    v = to[i];
    w = len[i];
    if (v != pre && w) {
      work(v, x, u);
      --len[i];
      return;
    }
  }
}
int main() {
  int x, v, w, ans = 0, i, j;
  rd(n);
  rd(m);
  cnt = n + m;
  S = 0;
  T = 55555;
  seg.build(1, 1, m);
  for (i = 1; i <= n; ++i) {
    scanf("%d", &q[i].opt);
    if (!q[i].opt) {
      scanf("%d", &q[i].k);
      ae(S, i + m, 1);
      for (j = 1; j <= q[i].k; ++j) {
        scanf("%d", &x);
        ae(i + m, x, 1);
      }
    } else if (q[i].opt == 1) {
      ae(S, i + m, 1);
      scanf("%d%d", &q[i].l, &q[i].r);
      seg.link(1, 1, m, q[i].l, q[i].r, i + m);
    } else if (q[i].opt == 2) {
      ae(S, i + m, 2);
      scanf("%d%d%d", &q[i].a, &q[i].b, &q[i].c);
      ae(i + m, q[i].a, 1);
      ae(i + m, q[i].b, 1);
      ae(i + m, q[i].c, 1);
    }
  }
  for (i = 1; i <= m; ++i) ae(i, T, 1);
  while (make_level()) ans += dinic(S, inf);
  printf("%d\n", ans);
  for (i = fir[T]; i; i = nxt[i]) {
    v = to[i];
    w = len[i];
    if (w) work(v, pos[v], T);
  }
  for (i = 1; i <= m; ++i) ++tot[pos[i]];
  for (i = 1; i <= n; ++i)
    if (q[i].opt == 2 && tot[i] == 1) {
      if (pos[q[i].a] != i)
        pos[q[i].a] = i;
      else
        pos[q[i].b] = i;
    }
  for (i = 1; i <= m; ++i)
    if (pos[i]) printf("%d %d\n", pos[i], i);
  return 0;
}