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;
int a, b, c, d, e, n, m, t, kk, tt = 0, l[5007], r[5007], fa[5007], type[5007],
                                ind[5007];
int y[5007] = {0}, qw[5007], tree[1000007], a1[5007], a2[5007], a3[5007],
    a4[5007];
vector<int> q[5007];
vector<short> w[5007];
void get(int x1, int l, int r, int tl, int tr, int k) {
  if (tree[k] == tt) return;
  if (l >= tl && r <= tr) {
    tree[k] = tt;
    for (int i = l; i <= r; i++) w[x1].push_back(i);
    return;
  }
  int m = (l + r) / 2;
  if (tl <= m) get(x1, l, m, tl, tr, k << 1);
  if (tr > m) get(x1, m + 1, r, tl, tr, (k << 1) + 1);
}
int sou(int x1) {
  t = 0;
  if (type[x1] == 0)
    for (int j = 1; j <= q[x1].size(); j++) w[x1].push_back(q[x1][j - 1]);
  else
    get(x1, 1, m, q[x1][0], q[x1][1], 1);
  for (int j = 1; j <= w[x1].size(); j++)
    if (!qw[fa[w[x1][j - 1]]]) {
      qw[fa[w[x1][j - 1]]] = 1;
      if (y[fa[w[x1][j - 1]]] == 0 || sou(y[fa[w[x1][j - 1]]])) {
        y[fa[w[x1][j - 1]]] = x1;
        w[x1].clear();
        return 1;
      }
    }
  w[x1].clear();
  return 0;
}
int main() {
  scanf("%d%d", &n, &m);
  kk = 1;
  for (int i = 1; i <= m; i++) fa[i] = i;
  int ans = 0, t3 = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &type[kk]);
    if (type[kk] == 0) {
      scanf("%d", &b);
      for (int j = 1; j <= b; j++) {
        scanf("%d", &c);
        q[kk].push_back(c);
      }
      ind[kk] = i;
      kk++;
    } else if (type[kk] == 1) {
      scanf("%d%d", &b, &c);
      ind[kk] = i;
      q[kk].push_back(b);
      q[kk++].push_back(c);
    } else {
      scanf("%d%d%d", &b, &c, &d);
      fa[c] = b;
      fa[d] = b;
      ans += 2;
      a1[++t3] = b, a2[t3] = c, a3[t3] = d, a4[t3] = i;
    }
  }
  for (int i = 1; i <= kk - 1; i++) {
    tt++;
    for (int j = 1; j <= m; j++) qw[j] = 0;
    if (sou(i)) ans++;
  }
  printf("%d\n", ans);
  for (int i = 1; i <= t3; i++) {
    fa[a1[i]] = 0;
    fa[a2[i]] = 0;
    fa[a3[i]] = 0;
    int g = 0;
    if (y[a1[i]] == 0) {
      printf("%d %d\n", a4[i], a1[i]);
      printf("%d %d\n", a4[i], a2[i]);
      continue;
    } else if (type[y[a1[i]]] == 0)
      for (int j = 1; j <= q[y[a1[i]]].size(); j++) {
        if (q[y[a1[i]]][j - 1] == a1[i]) g = 1;
        if (q[y[a1[i]]][j - 1] == a2[i]) g = 2;
        if (q[y[a1[i]]][j - 1] == a3[i]) g = 3;
      }
    else
      for (int j = q[y[a1[i]]][0]; j <= q[y[a1[i]]][1]; j++) {
        if (j == a1[i]) g = 1;
        if (j == a2[i]) g = 2;
        if (j == a3[i]) g = 3;
      }
    if (g == 1)
      printf("%d %d\n", ind[y[a1[i]]], a1[i]);
    else
      printf("%d %d\n", a4[i], a1[i]);
    if (g == 2)
      printf("%d %d\n", ind[y[a1[i]]], a2[i]);
    else
      printf("%d %d\n", a4[i], a2[i]);
    if (g == 3)
      printf("%d %d\n", ind[y[a1[i]]], a3[i]);
    else
      printf("%d %d\n", a4[i], a3[i]);
  }
  for (int i = 1; i <= m; i++)
    if (y[i] && fa[i] == i) printf("%d %d\n", ind[y[i]], i);
  return 0;
}