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 read() {
  int ans = 0, flag = 1;
  char ch = getchar();
  while (ch > '9' || ch < '0') {
    if (ch == '-') flag = -flag;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    ans = ans * 10 + ch - '0';
    ch = getchar();
  }
  return ans * flag;
}
const int N = 5010;
const int INF = 1000000000;
struct node {
  int id, l, r;
  bool operator<(const node a) { return r < a.r; }
} a[N];
int anum;
bool cmp(node a, node b) { return a.l < b.l; }
struct heap {
  int heapcnt = 0;
  node h[N];
  void push(node x) {
    h[++heapcnt] = x;
    int now = heapcnt;
    while (now / 2) {
      if (h[now] < h[now / 2]) {
        swap(h[now], h[now / 2]);
        now /= 2;
      } else
        break;
    }
  }
  void pop() {
    h[1] = (node){0, 0, 0};
    h[1] = h[heapcnt];
    h[heapcnt--] = (node){0, 0, 0};
    int now = 1, son = 2;
    while (son <= heapcnt) {
      if (son + 1 <= heapcnt && h[son + 1] < h[son]) ++son;
      if (h[son] < h[now]) {
        swap(h[son], h[now]);
        now = son;
        son = now * 2;
      } else
        break;
    }
  }
} q;
int n, m;
struct edge {
  int t, n, f;
} e[400010];
int head[4 * N], cur[4 * N], tot = 1;
void addedge(int u, int v, int w) {
  ++tot;
  e[tot].t = v;
  e[tot].n = head[u];
  e[tot].f = w;
  head[u] = tot;
  ++tot;
  e[tot].t = u;
  e[tot].n = head[v];
  e[tot].f = 0;
  head[v] = tot;
}
int ch[4 * N][2];
int id[4 * N];
int rt = 1, cnt = 1;
int s, t;
int d[4 * N];
int f[4 * N];
int opt[N];
int ll[N], rr[N];
int match[N];
void build(int &x, int l, int r) {
  if (!x) x = ++cnt;
  if (l == r) {
    id[x] = l;
    return;
  } else {
    build(ch[x][0], l, ((l + r) >> 1));
    build(ch[x][1], ((l + r) >> 1) + 1, r);
    addedge(x + n * 2, ch[x][0] + n * 2, INF);
    addedge(x + n * 2, ch[x][1] + n * 2, INF);
  }
}
void add(int x, int l, int r, int ll, int rr, int u) {
  if (l >= ll && r <= rr)
    addedge(u, x + n * 2, 1);
  else {
    if (((l + r) >> 1) >= ll) add(ch[x][0], l, ((l + r) >> 1), ll, rr, u);
    if (((l + r) >> 1) < rr) add(ch[x][1], ((l + r) >> 1) + 1, r, ll, rr, u);
  }
}
void buildedge(int x, int l, int r) {
  if (l == r)
    addedge(x + n * 2, t, 1);
  else {
    buildedge(ch[x][0], l, ((l + r) >> 1));
    buildedge(ch[x][1], ((l + r) >> 1) + 1, r);
  }
}
int dfs(int now, int flow) {
  if (now == t) return flow;
  int use = 0;
  for (int i = cur[now]; i; i = e[i].n) {
    cur[now] = i;
    if (e[i].f > 0 && d[e[i].t] + 1 == d[now]) {
      int tmp = dfs(e[i].t, min(e[i].f, flow - use));
      use += tmp;
      e[i].f -= tmp;
      e[i ^ 1].f += tmp;
      if (flow == use) return use;
    }
  }
  cur[now] = head[now];
  if (!--f[d[now]]) d[s] = 2 * n + cnt + 2;
  ++f[++d[now]];
  return use;
}
int main() {
  n = read();
  m = read();
  build(rt, 1, m);
  for (int i = 1; i <= n; ++i) {
    opt[i] = read();
    if (opt[i] == 0) {
      int k = read();
      addedge(i, i + n, 1);
      for (int j = 1; j <= k; ++j) {
        int pos = read();
        add(1, 1, m, pos, pos, i + n);
      }
    } else if (opt[i] == 1) {
      ll[i] = read();
      rr[i] = read();
      addedge(i, i + n, 1);
      add(1, 1, m, ll[i], rr[i], i + n);
    } else {
      int a = read(), b = read(), c = read();
      addedge(i, i + n, 2);
      add(1, 1, m, a, a, i + n);
      add(1, 1, m, b, b, i + n);
      add(1, 1, m, c, c, i + n);
    }
  }
  s = 2 * n + cnt + 1;
  t = 2 * n + cnt + 2;
  for (int i = 1; i <= n; ++i) addedge(s, i, INF);
  buildedge(1, 1, m);
  f[0] = 2 * n + cnt + 2;
  int ans = 0;
  while (d[s] < 2 * n + cnt + 2) ans += dfs(s, 1 << 30);
  printf("%d\n", ans);
  for (int i = head[t]; i; i = e[i].n) {
    if (e[i].f == 1)
      match[id[e[i].t - 2 * n]] = 0;
    else
      match[id[e[i].t - 2 * n]] = -1;
  }
  for (int i = 1; i <= n; ++i) {
    if (opt[i] == 2) {
      int nowflow = 0;
      for (int j = head[i + n]; j; j = e[j].n) {
        if (e[j].t > 2 * n && e[j].f == 0) {
          match[id[e[j].t - 2 * n]] = i;
          ++nowflow;
        }
      }
      if (nowflow == 2 || nowflow == 0) continue;
      for (int j = head[i + n]; j; j = e[j].n) {
        if (e[j].t > 2 * n && match[id[e[j].t - 2 * n]] == 0) {
          match[id[e[j].t - 2 * n]] = i;
          break;
        }
      }
    }
  }
  for (int i = 1; i <= n; ++i) {
    if (opt[i] == 0) {
      for (int j = head[i + n]; j; j = e[j].n) {
        if (e[j].t > 2 * n && e[j].f == 0 && match[id[e[j].t - 2 * n]] == 0) {
          match[id[e[j].t - 2 * n]] = i;
          break;
        }
      }
    }
  }
  for (int i = 1; i <= n; ++i)
    if (opt[i] == 1) a[++anum] = (node){i, ll[i], rr[i]};
  sort(a + 1, a + anum + 1, cmp);
  int top = 1;
  for (int i = 1; i <= m; ++i) {
    while (top <= anum && a[top].l <= i) q.push(a[top++]);
    while (q.heapcnt && q.h[1].r < i) {
      q.pop();
    }
    if (match[i] == 0 && q.heapcnt) {
      match[i] = q.h[1].id;
      q.pop();
    }
  }
  for (int i = 1; i <= m; ++i)
    if (match[i] != -1) printf("%d %d\n", match[i], i);
  return 0;
}