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 = 15005;
struct edge {
  int to, next, f;
} e[N * 100];
int head[N], tot = 1;
int n, m, S, T, nd, ls[N], rs[N], rt;
int dis[N], q[N], dep[N], sum[N];
int mat[N], id[N], tp[N];
vector<int> vec[N];
void add(int x, int y, int v) {
  e[++tot] = (edge){y, head[x], v};
  head[x] = tot;
  e[++tot] = (edge){x, head[y], 0};
  head[y] = tot;
}
bool bfs() {
  for (int i = (int)(1); i <= (int)(nd); i++) dis[i] = -1;
  int h = 0, t = 1;
  q[1] = S;
  dis[S] = 0;
  while (h != t) {
    int x = q[++h];
    for (int i = head[x]; i; i = e[i].next)
      if (dis[e[i].to] == -1 && e[i].f) {
        dis[e[i].to] = dis[x] + 1;
        if (e[i].to == T) return 1;
        q[++t] = e[i].to;
      }
  }
  return 0;
}
int dfs(int x, int flow) {
  if (x == T) return flow;
  int k, rest = flow;
  for (int i = head[x]; i && rest; i = e[i].next)
    if (dis[e[i].to] == dis[x] + 1 && e[i].f) {
      k = dfs(e[i].to, min(rest, e[i].f));
      e[i].f -= k;
      e[i ^ 1].f += k;
      rest -= k;
    }
  if (rest) dis[x] = -1;
  return flow - rest;
}
int build_tr(int l, int r, int d) {
  if (l == r) return l;
  int mid = (l + r) / 2, x = ++nd;
  add(x, ls[x] = build_tr(l, mid, d - 1), 1 << 30);
  add(x, rs[x] = build_tr(mid + 1, r, d - 1), 1 << 30);
  dep[x] = d;
  return x;
}
void add_e(int k, int l, int r, int x, int y, int p) {
  if (x <= l && r <= y) {
    add(p, k, 1);
    return;
  }
  int mid = (l + r) / 2;
  if (x <= mid) add_e(ls[k], l, mid, x, y, p);
  if (y > mid) add_e(rs[k], mid + 1, r, x, y, p);
}
void recover(int x, int id1, int id2) {
  if (x == T) {
    assert(id1 > 0 && id2 < 0);
    mat[-id2] = id1;
    return;
  }
  if (id[x]) id1 ? id2 = id[x] : id1 = id[x];
  for (int i = head[x]; i; i = e[i].next)
    if (dep[e[i].to] < dep[x] && e[i ^ 1].f) {
      e[i ^ 1].f--, e[i].f++;
      recover(e[i].to, id1, id2);
      return;
    }
  assert(0);
}
int main() {
  scanf("%d%d", &n, &m);
  nd = m;
  S = ++nd;
  T = ++nd;
  dep[S] = 10000;
  dep[T] = 0;
  for (int i = (int)(1); i <= (int)(m); i++)
    add(i, T, 1), id[i] = -i, dep[i] = 1;
  rt = build_tr(1, m, 1000);
  for (int i = (int)(1); i <= (int)(n); i++) {
    scanf("%d", &tp[i]);
    if (tp[i] == 0) {
      int cnt, x;
      scanf("%d", &cnt);
      id[++nd] = i;
      dep[nd] = 2333;
      for (; cnt; --cnt) {
        scanf("%d", &x);
        add(nd, x, 1);
      }
      add(S, nd, 1);
    }
    if (tp[i] == 1) {
      int l, r;
      scanf("%d%d", &l, &r);
      id[++nd] = i;
      dep[nd] = 2333;
      add_e(rt, 1, m, l, r, nd);
      add(S, nd, 1);
    }
    if (tp[i] == 2) {
      id[++nd] = i;
      dep[nd] = 2333;
      for (int j = (int)(1); j <= (int)(3); j++) {
        int x;
        scanf("%d", &x);
        vec[i].push_back(x);
        add(nd, x, 1);
      }
      add(S, nd, 2);
    }
  }
  int ans = 0;
  for (; bfs(); ans += dfs(S, 1 << 30))
    ;
  for (int i = (int)(1); i <= (int)(ans); i++) recover(S, 0, 0);
  for (int i = (int)(1); i <= (int)(m); i++)
    if (mat[i]) ++sum[mat[i]];
  for (int i = (int)(1); i <= (int)(n); i++)
    if (tp[i] == 2 && sum[i] == 1) {
      int y = (mat[vec[i][0]] == i);
      mat[vec[i][y]] = i;
    }
  printf("%d\n", ans);
  for (int i = (int)(1); i <= (int)(m); i++)
    if (mat[i]) printf("%d %d\n", mat[i], i);
}