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>
const int S = 5005 * 2, N = 5005 * 3, M = (150000 + 100000) * 2,
          INF = 0x3f3f3f3f;
int n, tot, Fr, To, A[5005], B[5005], C[5005], cnt[5005], son[S][2];
int src, des, Enum, cur[N], H[N], nxt[M], to[M], cap[M], fr[M], pre[N], num[N],
    lev[N];
std::vector<std::pair<int, int> > ans, e[N];
char IN[100000], *SS = IN, *TT = IN;
inline int read() {
  int now = 0;
  register char c = getchar();
  for (; !isdigit(c); c = getchar())
    ;
  for (; isdigit(c); now = now * 10 + c - '0', c = getchar())
    ;
  return now;
}
inline void AE(int u, int v, int w) {
  to[++Enum] = u, nxt[Enum] = H[v], H[v] = Enum, cap[Enum] = 0, fr[Enum] = v;
  to[++Enum] = v, nxt[Enum] = H[u], H[u] = Enum, cap[Enum] = w, fr[Enum] = u;
}
void Build(int &x, int l, int r) {
  if (l == r) {
    x = l;
    return;
  }
  x = ++tot;
  int m = l + r >> 1;
  Build(son[x][0], l, m), Build(son[x][1], m + 1, r);
  AE(x, son[x][0], INF), AE(x, son[x][1], INF);
}
void Insert(int x, int l, int r, int L, int R, int s) {
  if (L <= l && r <= R) {
    AE(s, x, 1);
    return;
  }
  int m = l + r >> 1;
  if (L <= m) Insert(son[x][0], l, m, L, R, s);
  if (m < R) Insert(son[x][1], m + 1, r, L, R, s);
}
bool BFS() {
  static int q[N];
  for (int i = 0; i <= tot; ++i) lev[i] = tot + 1;
  int h = 0, t = 1;
  lev[des] = 0, q[0] = des;
  while (h < t) {
    int x = q[h++];
    for (int i = H[x]; i; i = nxt[i]) {
      if (lev[to[i]] == tot + 1 && cap[i ^ 1])
        lev[to[i]] = lev[x] + 1, q[t++] = to[i];
    }
  }
  return lev[src] <= tot;
}
inline int Augment() {
  for (int i = des; i; i = fr[pre[i]]) --cap[pre[i]], ++cap[pre[i] ^ 1];
  return 1;
}
int ISAP() {
  if (!BFS()) return 0;
  for (int i = 0; i <= tot; ++i) ++num[lev[i]], cur[i] = H[i];
  int res = 0, x = 0;
  while (lev[src] <= tot) {
    if (x == des) res += Augment(), x = 0;
    bool can = 0;
    for (int i = cur[x]; i; i = nxt[i])
      if (lev[to[i]] == lev[x] - 1 && cap[i]) {
        can = 1, cur[x] = i, pre[x = to[i]] = i;
        break;
      }
    if (!can) {
      int mn = tot;
      for (int i = H[x]; i; i = nxt[i])
        if (cap[i]) mn = std::min(mn, lev[to[i]]);
      if (!--num[lev[x]]) break;
      ++num[lev[x] = mn + 1], cur[x] = H[x];
      if (x) x = fr[pre[x]];
    }
  }
  return res;
}
bool DFS(int x) {
  if (x == des) return 1;
  for (int i = 0, l = e[x].size(); i < l; ++i)
    if (e[x][i].second) {
      if (!DFS(e[x][i].first)) continue;
      --e[x][i].second;
      if (!x) Fr = e[x][i].first;
      if (e[x][i].first == des) To = x;
      return 1;
    }
  return 0;
}
int main() {
  n = read();
  int m = read(), root = 0;
  Enum = 1, tot = m, Build(root, 1, m), src = 0, des = ++tot;
  for (int i = 1; i <= m; ++i) AE(i, des, 1);
  for (int i = 1, p = tot + 1, opt, l, r; i <= n; ++i, ++p)
    if (!(opt = read())) {
      AE(0, p, 1);
      for (int k = read(); k--; AE(p, read(), 1))
        ;
    } else if (opt == 1)
      l = read(), r = read(), AE(0, p, 1), Insert(root, 1, m, l, r, p);
    else
      AE(0, p, 2), AE(p, A[i] = read(), 1), AE(p, B[i] = read(), 1),
          AE(p, C[i] = read(), 1);
  int tmp = tot;
  tot += n;
  int flow = ISAP();
  printf("%d\n", flow);
  for (int i = 2; i <= Enum; i += 2)
    e[to[i]].push_back(std::make_pair(fr[i], cap[i]));
  for (int i = 1; i <= flow; ++i)
    Fr = 0, DFS(0), ans.push_back(std::make_pair(Fr - tmp, To)),
    ++cnt[Fr - tmp];
  int size = ans.size();
  for (int i = 1; i <= n; ++i)
    if (A[i] && cnt[i] == 1)
      for (int j = 0; j < size; ++j)
        if (ans[j].first != i &&
            (ans[j].second == A[i] || ans[j].second == B[i] ||
             ans[j].second == C[i])) {
          ans[j].first = i;
          break;
        }
  for (int i = 0; i < size; ++i) printf("%d %d\n", ans[i].first, ans[i].second);
  return 0;
}