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;
inline int read() {
  int x = 0, fu = 0;
  char ch = getchar();
  for (; ch < 48 || ch > 57; ch = getchar()) fu |= (ch == '-');
  for (; ch > 47 && ch < 58; ch = getchar()) x = x * 10 + ch - '0';
  return fu ? -x : x;
}
const int inf = 0x3f3f3f3f;
struct Network_Flow {
  int st, ed, head[100005], eot;
  Network_Flow() { eot = 1; }
  struct edge {
    int t, nxt, w;
  } e[400005];
  void add(int u, int v, int w) {
    e[++eot] = (edge){v, head[u], w};
    head[u] = eot;
    e[++eot] = (edge){u, head[v], 0};
    head[v] = eot;
  }
  int q[100005], hd, tl, d[100005];
  bool bfs() {
    memset(d, -1, sizeof(d));
    hd = tl = 0, q[++tl] = st, d[st] = 1;
    for (int x, i; hd < tl;) {
      for (x = q[++hd], i = head[x]; i; i = e[i].nxt)
        if (d[e[i].t] == -1 && e[i].w) d[e[i].t] = d[x] + 1, q[++tl] = e[i].t;
    }
    return d[ed] != -1;
  }
  int dfs(int u, int v, int w) {
    if (u == v) return w;
    int ret = 0;
    for (int i = head[u]; i; i = e[i].nxt)
      if (e[i].w && ret < w && d[e[i].t] == d[u] + 1) {
        int flow = dfs(e[i].t, v, min(w - ret, e[i].w));
        e[i].w -= flow, e[i ^ 1].w += flow, ret += flow;
      }
    if (!ret) d[u] = -2;
    return ret;
  }
  int dinic() {
    int ret = 0;
    while (bfs()) ret += dfs(st, ed, inf);
    return ret;
  }
} wll;
int n, m, tot, M, ans[5005];
struct seg_tree {
  int Id[20005];
  void build(int id, int l, int r) {
    if (l == r) {
      Id[id] = l;
      return;
    }
    int mid = (l + r) >> 1;
    Id[id] = ++tot;
    build(id << 1, l, mid);
    build(id << 1 | 1, mid + 1, r);
    wll.add(Id[id], Id[id << 1], Id[id << 1] > m ? inf : 1);
    wll.add(Id[id], Id[id << 1 | 1], Id[id << 1 | 1] > m ? inf : 1);
  }
  void link(int id, int l, int r, int ql, int qr, int fr) {
    if (l == ql && r == qr) {
      wll.add(fr, Id[id], 1);
      return;
    }
    int mid = (l + r) >> 1;
    if (mid >= qr)
      link(id << 1, l, mid, ql, qr, fr);
    else if (mid < ql)
      link(id << 1 | 1, mid + 1, r, ql, qr, fr);
    else
      link(id << 1, l, mid, ql, mid, fr),
          link(id << 1 | 1, mid + 1, r, mid + 1, qr, fr);
  }
  vector<int> Empty;
  vector<int> getans(int id, int l, int r) {
    if (l == r) return Empty;
    int mid = (l + r) >> 1;
    vector<int> L = getans(id << 1, l, mid);
    vector<int> R = getans(id << 1 | 1, mid + 1, r);
    vector<int> now;
    set_union(L.begin(), L.end(), R.begin(), R.end(), back_inserter(now));
    for (int i = wll.head[Id[id]]; i; i = wll.e[i].nxt) {
      if (wll.e[i].t <= m && wll.e[i].w == 0) now.push_back(wll.e[i].t);
    }
    for (int i = wll.head[Id[id]]; i; i = wll.e[i].nxt) {
      if (wll.e[i].t > M && wll.e[i].w)
        ans[now[now.size() - 1]] = wll.e[i].t - M, now.pop_back();
    }
    return now;
  }
} s;
int iD[5005], op0[5005], tp0, op2[5005], tp2, from[5005];
int main() {
  n = read(), tot = m = read();
  s.build(1, 1, m), M = tot;
  wll.st = M + n + 1, wll.ed = M + n + 2;
  for (int i = 1; i <= m; i++) wll.add(i, wll.ed, 1);
  for (int i = 1, op, x, y, z; i <= n; i++) {
    op = read(), iD[i] = ++tot, wll.add(wll.st, tot, op == 2 ? 2 : 1);
    from[i] = wll.eot - 1;
    if (!op) {
      op0[++tp0] = i, x = read();
      while (x--) y = read(), wll.add(tot, y, 1);
    } else if (op ^ 2) {
      op0[++tp0] = i, x = read(), y = read(), s.link(1, 1, m, x, y, tot);
    } else {
      x = read(), y = read(), z = read(), op2[++tp2] = i;
      wll.add(tot, x, 1), wll.add(tot, y, 1), wll.add(tot, z, 1);
    }
  }
  printf("%d\n", wll.dinic());
  for (int i = 1; i <= tp0; i++)
    for (int j = wll.head[iD[op0[i]]]; j; j = wll.e[j].nxt)
      if (wll.e[j].t <= m && wll.e[j ^ 1].w) ans[wll.e[j].t] = op0[i];
  s.getans(1, 1, m);
  for (int I = 1, i = op2[I]; I <= tp2; I++, i = op2[I]) {
    for (int j = wll.head[iD[i]]; j; j = wll.e[j].nxt)
      if (wll.e[j].t <= m && !wll.e[j].w) ans[wll.e[j].t] = i;
    if (wll.e[from[i]].w == 1)
      for (int j = wll.head[iD[i]]; j; j = wll.e[j].nxt)
        if (wll.e[j].t != wll.st && wll.e[j].w) {
          ans[wll.e[j].t] = i;
          break;
        }
  }
  for (int i = 1; i <= m; i++)
    if (ans[i]) printf("%d %d\n", ans[i], i);
  return 0;
}