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 n, m, S, T, ans, rt, cnt, lc[20000], rc[20000], pos[20000];
int tag[20000], A[20000][3], from[20000], dep[20000], q[20000];
int k = 1, la[20000], ff[400000], cur[20000], ss[20000];
struct node {
  int a, b, c;
} e[400000];
void add(int a, int b, int c) {
  e[++k] = (node){a, b, c};
  ff[k] = la[a];
  la[a] = k;
  e[++k] = (node){b, a, 0};
  ff[k] = la[b];
  la[b] = k;
}
int dfs(int x, int flow) {
  if (x == T) return flow;
  int res = 0, tmp;
  for (int a = cur[x]; a && flow; a = ff[a]) {
    cur[x] = a;
    if (dep[e[a].b] == dep[x] + 1 && e[a].c) {
      tmp = dfs(e[a].b, min(flow, e[a].c));
      e[a].c -= tmp;
      e[a ^ 1].c += tmp;
      res += tmp;
      flow -= tmp;
    }
  }
  if (!res) dep[x] = -1;
  return res;
}
bool bfs() {
  memset(dep, 0, sizeof(dep));
  for (int i = S; i <= T; i++) cur[i] = la[i];
  int l = 1, r = 2;
  q[1] = S;
  dep[S] = 1;
  while (l < r) {
    int x = q[l];
    l++;
    for (int a = la[x]; a; a = ff[a])
      if (!dep[e[a].b] && e[a].c) q[r] = e[a].b, dep[q[r]] = dep[x] + 1, r++;
  }
  return dep[T];
}
void build(int &x, int l, int r, int pre) {
  if (!x) x = ++cnt;
  if (pre) add(pre, x, r - l + 1);
  if (l == r) {
    pos[l] = x;
    return;
  }
  int mid = l + r >> 1;
  build(lc[x], l, mid, x);
  build(rc[x], mid + 1, r, x);
}
void solve(int x, int l, int r, int ql, int qr, int S) {
  if (ql <= l && r <= qr) {
    add(S, x, 1);
    return;
  }
  int mid = l + r >> 1;
  if (ql <= mid) solve(lc[x], l, mid, ql, qr, S);
  if (qr > mid) solve(rc[x], mid + 1, r, ql, qr, S);
}
int find(int x, int flow, int pos) {
  if (x == T) return flow;
  int res = 0, tmp;
  for (int a = la[x]; a; a = ff[a])
    if (!(a & 1) && e[a ^ 1].c) {
      tmp = find(e[a].b, min(flow, e[a ^ 1].c), pos);
      e[a ^ 1].c -= tmp;
      e[a].c += tmp;
      res += tmp;
      flow -= tmp;
      if (e[a].b == T) from[x] = pos;
    }
  return res;
}
int main() {
  int tp, x, len, l, r, a, b, c;
  scanf("%d%d", &n, &m);
  cnt = n;
  build(rt, 1, m, 0);
  T = cnt + 1;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &tp);
    cnt++;
    if (tp == 0) {
      scanf("%d", &len);
      add(S, i, 1);
      for (int j = 1; j <= len; j++) scanf("%d", &x), add(i, pos[x], 1);
    }
    if (tp == 1) {
      scanf("%d%d", &l, &r);
      add(S, i, 1);
      solve(rt, 1, m, l, r, i);
    }
    if (tp == 2) {
      scanf("%d%d%d", &a, &b, &c);
      tag[i] = 1;
      A[i][0] = a;
      A[i][1] = b;
      A[i][2] = c;
      add(S, i, 2);
      add(i, pos[a], 1);
      add(i, pos[b], 1);
      add(i, pos[c], 1);
    }
  }
  for (int i = 1; i <= m; i++) add(pos[i], T, 1);
  while (bfs()) ans += dfs(S, 1050000000);
  for (int a = la[S]; a; a = ff[a])
    if (e[a ^ 1].c) find(e[a].b, e[a ^ 1].c, e[a].b);
  for (int i = 1; i <= m; i++) ss[from[pos[i]]]++;
  for (int i = 1; i <= n; i++)
    if (tag[i] && ss[i] == 1) {
      int flag = 0;
      for (int j = 0; j <= 2; j++)
        if (from[pos[A[i][j]]] && from[pos[A[i][j]]] != i) {
          from[pos[A[i][j]]] = i;
          flag = 1;
          break;
        }
      if (flag) continue;
      for (int j = 0; j <= 2; j++) from[pos[A[i][j]]] = 0;
      ans--;
    }
  printf("%d\n", ans);
  for (int i = 1; i <= m; i++)
    if (from[pos[i]]) printf("%d %d\n", from[pos[i]], i);
  return 0;
}