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 N = 200100, p = N / 2;
int n, m, id[N], head[N], Next[N << 1], ver[N << 1], c[N << 1],
    tot = 1, dep[N], s, t, cur[N], ans, fa[N], cnt[N], is[N], son[N][5];
queue<int> q;
struct TREE {
  int l, r;
} tree[N];
void read(int x, int y, int z) {
  ver[++tot] = y;
  Next[tot] = head[x];
  head[x] = tot;
  c[tot] = z;
}
void build(int x, int l, int r) {
  tree[x].l = l;
  tree[x].r = r;
  if (l == r) {
    id[l] = x;
    read(x, t, 1);
    read(t, x, 0);
    return;
  }
  read(x, (x << 1), 1000000000), read((x << 1), x, 0);
  read(x, ((x << 1) + 1), 1000000000), read(((x << 1) + 1), x, 0);
  int mid = (l + r) >> 1;
  build((x << 1), l, mid);
  build(((x << 1) + 1), mid + 1, r);
  return;
}
void query(int x, int l, int r, int from) {
  if (tree[x].l >= l && tree[x].r <= r) {
    read(from, x, 1000000000);
    read(x, from, 0);
    return;
  }
  int mid = (tree[x].l + tree[x].r) >> 1;
  if (l <= mid) query((x << 1), l, r, from);
  if (r > mid) query(((x << 1) + 1), l, r, from);
}
bool bfs() {
  memset(dep, 0, sizeof(dep));
  dep[s] = 1;
  q.push(s);
  while (!q.empty()) {
    int x = q.front();
    q.pop();
    cur[x] = head[x];
    for (int i = head[x]; i; i = Next[i]) {
      int y = ver[i];
      if (dep[y] || !c[i]) continue;
      dep[y] = dep[x] + 1;
      q.push(y);
    }
  }
  if (dep[t])
    return true;
  else
    return false;
}
int dfs(int x, int sum) {
  if (x == t) return sum;
  int liu = 0;
  for (int i = cur[x]; i; i = Next[i]) {
    int y = ver[i];
    if (dep[y] != dep[x] + 1) continue;
    int now;
    now = dfs(y, min(c[i], sum));
    liu += now;
    sum -= now;
    c[i] -= now;
    c[i ^ 1] += now;
    if (sum <= 0) break;
    cur[x] = Next[i];
  }
  return liu;
}
void Dinic() {
  while (bfs()) {
    ans += dfs(s, 1000000000);
  }
}
void find_fa(int x, int &o) {
  if (x > p && x < t) o = x - p;
  if (o) return;
  for (int i = head[x]; i; i = Next[i]) {
    int y = ver[i];
    if ((i & 1) == 0 || !c[i]) continue;
    find_fa(y, o);
    c[i]--;
    return;
  }
}
int main() {
  cin >> n >> m;
  s = 0, t = N - 2;
  build(1, 1, m);
  for (int i = 1; i <= n; i++) {
    int op;
    scanf("%d", &op);
    if (op == 0) {
      int k;
      scanf("%d", &k);
      read(s, i + p, 1), read(i + p, s, 0);
      for (int j = 1; j <= k; j++) {
        int x;
        scanf("%d", &x);
        read(i + p, id[x], 1), read(id[x], i + p, 0);
      }
    }
    if (op == 1) {
      read(s, i + p, 1), read(i + p, s, 0);
      int l, r;
      scanf("%d%d", &l, &r);
      query(1, l, r, i + p);
    }
    if (op == 2) {
      read(s, i + p, 2), read(i + p, s, 0);
      is[i] = 1;
      int a, b, c;
      scanf("%d%d%d", &a, &b, &c);
      read(i + p, id[a], 1), read(id[a], i + p, 0);
      read(i + p, id[b], 1), read(id[b], i + p, 0);
      read(i + p, id[c], 1), read(id[c], i + p, 0);
      son[i][1] = a;
      son[i][2] = b;
      son[i][3] = c;
    }
  }
  Dinic();
  for (int i = head[t]; i; i = Next[i]) {
    if (c[i]) find_fa(ver[i], fa[ver[i]]);
    cnt[fa[ver[i]]]++;
  }
  cout << ans << endl;
  for (int i = 1; i <= m; i++) {
    if (!fa[id[i]]) continue;
    if (cnt[fa[id[i]]] == 1 && is[fa[id[i]]]) {
      cnt[fa[id[i]]]++;
      for (int j = 1; j <= 3; j++) {
        if (son[fa[id[i]]][j] == i) continue;
        fa[id[son[fa[id[i]]][j]]] = fa[id[i]];
        break;
      }
    }
  }
  for (int i = 1; i <= m; i++) {
    if (!fa[id[i]]) continue;
    printf("%d %d\n", fa[id[i]], i);
  }
  return 0;
}