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 INF = 0x7fffffff;
struct edge {
  int u, v, c;
} e[1000005];
int head[1000005], cur[1000005], nxt[10000005], cnt = 1;
void insert(int u, int v, int c) {
  e[++cnt] = (edge){u, v, c};
  nxt[cnt] = head[u];
  head[u] = cnt;
}
void addnode(int u, int v, int c) { insert(u, v, c), insert(v, u, 0); }
int dis[1000005], S, T;
bool bfs() {
  queue<int> q;
  q.push(S);
  memset(dis, -1, (T + 5) * sizeof(int));
  dis[S] = 0;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int i = head[u]; i; i = nxt[i])
      if (e[i].c && dis[e[i].v] == -1) {
        dis[e[i].v] = dis[u] + 1;
        q.push(e[i].v);
        if (e[i].v == T) return true;
      }
  }
  return false;
}
int dfs(int u, int f) {
  if (u == T || !f) return f;
  int used = 0;
  for (int &i = cur[u]; i; i = nxt[i])
    if (e[i].c && dis[e[i].v] == dis[u] + 1) {
      int w = dfs(e[i].v, min(f, e[i].c));
      if (!w) continue;
      used += w, f -= w;
      e[i].c -= w, e[i ^ 1].c += w;
      if (!f) break;
    }
  if (!used) dis[u] = -1;
  return used;
}
inline int dinic() {
  int mflow = 0;
  while (bfs()) memcpy(cur, head, (T + 5) * sizeof(int)), mflow += dfs(S, INF);
  return mflow;
}
int pos[1000005], sop[1000005], mx;
void build(int p, int l, int r) {
  mx = max(mx, p);
  if (l == r) return (void)(pos[l] = p, sop[p] = l);
  int mid = (l + r) >> 1;
  build(p << 1, l, mid);
  build(p << 1 | 1, mid + 1, r);
  addnode(p, p << 1, INF), addnode(p, p << 1 | 1, INF);
}
void query(int p, int l, int r, int ql, int qr, int u) {
  if (ql <= l && r <= qr) return (void)addnode(u, p, 1);
  if (qr < l || r < ql) return;
  int mid = (l + r) >> 1;
  query(p << 1, l, mid, ql, qr, u), query(p << 1 | 1, mid + 1, r, ql, qr, u);
}
int x[1000005], a[1000005], b[1000005], c[1000005], tot, n, m;
int ans[1000005];
int find(int u, int f) {
  if (mx + 1 <= u && u <= mx + n) return u;
  for (int i = head[u]; i; i = nxt[i])
    if (e[i].c && e[i].v != f) {
      --e[i].c;
      ++e[i ^ 1].c;
      return find(e[i].v, u);
    }
  return 0;
}
int main() {
  scanf("%d%d", &n, &m);
  build(1, 1, m);
  S = mx + n + 1, T = S + 1;
  for (int i = 1; i <= n; i++) {
    int type;
    scanf("%d", &type);
    if (type == 0) {
      addnode(S, mx + i, 1);
      int k;
      scanf("%d", &k);
      while (k--) {
        int x;
        scanf("%d", &x);
        addnode(mx + i, pos[x], 1);
      }
    }
    if (type == 1) {
      addnode(S, mx + i, 1);
      int l, r;
      scanf("%d%d", &l, &r);
      query(1, 1, m, l, r, mx + i);
    }
    if (type == 2) {
      ++tot;
      x[tot] = i;
      scanf("%d%d%d", &a[tot], &b[tot], &c[tot]);
    }
  }
  for (int i = 1; i <= tot; i++) {
    addnode(S, mx + x[i], 2);
    addnode(mx + x[i], pos[a[i]], 1);
    addnode(mx + x[i], pos[b[i]], 1);
    addnode(mx + x[i], pos[c[i]], 1);
  }
  for (int i = 1; i <= m; i++) addnode(pos[i], T, 1);
  printf("%d\n", dinic());
  for (int i = head[T]; i; i = nxt[i])
    if (e[i].c) {
      int t = find(e[i].v, T);
      if (t) printf("%d %d\n", t - mx, sop[e[i].v]);
    }
  return 0;
}