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 maxn = 5010;
const int inf = 0x3f3f3f3f;
int n, m;
namespace netflow {
struct Edge {
  int v, c, x;
} E[6000010];
int src, sink;
int l[10 * maxn], e = 0;
int L[10 * maxn], Q[10 * maxn];
inline void addEdge(int u, int v, int f, int invf) {
  E[e].v = v;
  E[e].x = l[u];
  E[e].c = f;
  l[u] = e++;
  E[e].v = u;
  E[e].x = l[v];
  E[e].c = invf;
  l[v] = e++;
}
int _bfs() {
  for (int i = 1; i < 10 * maxn; i++) L[i] = -1;
  int s = 0, t = 0, u;
  Q[t++] = src;
  L[src] = 0;
  while (s < t) {
    u = Q[s++];
    for (int p = l[u]; p >= 0; p = E[p].x) {
      int v = E[p].v;
      if (L[v] == -1 && E[p].c) {
        L[Q[t++] = v] = L[u] + 1;
      }
    }
  }
  return L[sink] != -1;
}
int _find(int u, int in) {
  if (u == sink) return in;
  int w = 0, t;
  for (int p = l[u]; p >= 0 && w < in; p = E[p].x) {
    int v = E[p].v;
    if (L[v] == L[u] + 1 && E[p].c) {
      if ((t = _find(v, min(in - w, E[p].c)))) {
        E[p].c -= t;
        E[p ^ 1].c += t;
        w += t;
      }
    }
  }
  if (w < in) L[u] = -1;
  return w;
}
int dinic() {
  int res = 0, t;
  while (_bfs())
    while ((t = _find(src, 0x3f3f3f3f))) res += t;
  return res;
}
void init() {
  e = 0;
  memset(l, -1, sizeof(l));
  src = 1;
  sink = 2;
}
}  // namespace netflow
using namespace netflow;
void build(int l, int r, int rt) {
  if (l == r) {
    addEdge(2 + n + m + rt, 2 + n + l, 1, 0);
    return;
  }
  int mid = (l + r) >> 1;
  addEdge(2 + n + m + rt, 2 + n + m + (rt << 1), inf, 0);
  addEdge(2 + n + m + rt, 2 + n + m + (rt << 1 | 1), inf, 0);
  build(l, mid, rt << 1);
  build(mid + 1, r, rt << 1 | 1);
}
void add(int L, int R, int x, int l, int r, int rt) {
  if (L <= l && r <= R) {
    addEdge(x, 2 + n + m + rt, 1, 0);
    return;
  }
  int mid = (l + r) >> 1;
  if (L <= mid) add(L, R, x, l, mid, rt << 1);
  if (R > mid) add(L, R, x, mid + 1, r, rt << 1 | 1);
}
int gettarget(int x) {
  if (x >= 2 + n + 1 && x <= 2 + n + m) {
    return x - 2 - n;
  }
  for (int p = l[x]; p >= 0; p = E[p].x) {
    if (p & 1) continue;
    int v = E[p].v;
    if (E[p ^ 1].c) {
      E[p ^ 1].c--;
      return gettarget(v);
    }
  }
  return -1;
}
int active[maxn];
int frm[maxn];
int T[maxn], A[maxn], B[maxn], C[maxn];
int main() {
  scanf("%d%d", &n, &m);
  init();
  for (int i = 1; i <= m; i++) {
    addEdge(2 + n + i, 2, 1, 0);
  }
  build(1, m, 1);
  for (int i = 1; i <= n; i++) {
    int typ;
    scanf("%d", &typ);
    if (typ == 0) {
      addEdge(1, 2 + i, 1, 0);
      int K = 0;
      scanf("%d", &K);
      for (int j = 1; j <= K; j++) {
        int x = 0;
        scanf("%d", &x);
        addEdge(2 + i, 2 + n + x, 1, 0);
      }
    } else if (typ == 1) {
      addEdge(1, 2 + i, 1, 0);
      int L, R;
      scanf("%d%d", &L, &R);
      add(L, R, 2 + i, 1, m, 1);
    } else {
      addEdge(1, 2 + i, 2, 0);
      int a, b, c;
      scanf("%d%d%d", &a, &b, &c);
      A[i] = a;
      B[i] = b;
      C[i] = c;
      T[i] = 1;
      addEdge(2 + i, 2 + n + a, 1, 0);
      addEdge(2 + i, 2 + n + b, 1, 0);
      addEdge(2 + i, 2 + n + c, 1, 0);
    }
  }
  dinic();
  for (int i = 1; i <= n; i++) {
    int t = gettarget(2 + i);
    if (t != -1) {
      frm[t] = i;
    }
    if (T[i]) {
      t = gettarget(2 + i);
      if (t != -1) {
        frm[t] = i;
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    if (T[i]) {
      int x = (frm[A[i]] == i) + (frm[B[i]] == i) + (frm[C[i]] == i);
      if (x == 1) {
        if (frm[A[i]] != i) {
          frm[A[i]] = i;
        } else if (frm[B[i]] != i) {
          frm[B[i]] = i;
        } else if (frm[C[i]] != i) {
          frm[C[i]] = i;
        }
      }
    }
  }
  int X = 0;
  for (int i = 1; i <= m; i++)
    if (frm[i]) ++X;
  printf("%d\n", X);
  for (int i = 1; i <= m; i++) {
    if (frm[i]) printf("%d %d\n", frm[i], i);
  }
  return 0;
}