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, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 3) + (x << 1) + (ch ^ 48);
    ch = getchar();
  }
  return x * f;
}
struct arr {
  int x, y, z;
} a[200005];
int n, m, S, T;
int head[200005], head_[200005], nxt[400005], v[400005], w[400005], cnt = 1;
inline void add(int x, int y, int z) {
  v[++cnt] = y;
  w[cnt] = z;
  nxt[cnt] = head[x];
  head[x] = cnt;
}
inline void add_(int x, int y, int z) {
  add(x, y, z);
  add(y, x, 0);
}
int pos[200005 << 2], pos_[200005 << 2], mx;
inline void build(int rt, int l, int r) {
  mx = max(mx, rt);
  if (l == r) {
    pos[l] = rt;
    pos_[rt] = l;
    return;
  }
  build((rt << 1), l, ((l + r) >> 1));
  build(((rt << 1) | 1), ((l + r) >> 1) + 1, r);
  add_(rt, (rt << 1), 2e9);
  add_(rt, ((rt << 1) | 1), 2e9);
}
inline void query(int rt, int l, int r, int p, int q, int P) {
  if (l == p && r == q) {
    add_(P, rt, 1);
    return;
  }
  if (q <= ((l + r) >> 1))
    query((rt << 1), l, ((l + r) >> 1), p, q, P);
  else if (((l + r) >> 1) + 1 <= p)
    query(((rt << 1) | 1), ((l + r) >> 1) + 1, r, p, q, P);
  else
    query((rt << 1), l, ((l + r) >> 1), p, ((l + r) >> 1), P),
        query(((rt << 1) | 1), ((l + r) >> 1) + 1, r, ((l + r) >> 1) + 1, q, P);
}
queue<int> q;
int dis[200005];
inline bool bfs() {
  while (!q.empty()) q.pop();
  q.push(S);
  memset(dis, -1, sizeof(dis));
  dis[S] = 0;
  while (!q.empty()) {
    int x = q.front();
    q.pop();
    for (int i = head[x]; i; i = nxt[i])
      if (w[i] && dis[v[i]] == -1) {
        dis[v[i]] = dis[x] + 1;
        q.push(v[i]);
        if (v[i] == T) return 1;
      }
  }
  return 0;
}
inline int dfs(int x, int flow) {
  if (x == T || !flow) return flow;
  int used = 0;
  for (int &i = head_[x]; i; i = nxt[i])
    if (w[i] && dis[v[i]] == dis[x] + 1) {
      int W = dfs(v[i], min(w[i], flow));
      if (!W) continue;
      used += W;
      flow -= W;
      w[i] -= W;
      w[i ^ 1] += W;
      if (!flow) break;
    }
  if (!used) dis[x] = -1;
  return used;
}
inline int dinic() {
  int flow = 0;
  while (bfs()) memcpy(head_, head, sizeof(head_)), flow += dfs(S, 2e9);
  return flow;
}
inline int find(int x, int fa) {
  if (mx + 1 <= x && x <= mx + n) return x;
  for (int i = head[x]; i; i = nxt[i])
    if (w[i] && v[i] != fa) {
      w[i]--;
      w[i ^ 1]++;
      return find(v[i], x);
    }
}
int o[200005], tot;
int main() {
  n = read();
  m = read();
  build(1, 1, m);
  S = mx + n + 1;
  T = S + 1;
  int opt, x, y, z;
  for (int i = 1; i <= n; i++) {
    opt = read();
    if (opt == 0) {
      x = read();
      add_(S, mx + i, 1);
      while (x--) y = read(), add_(mx + i, pos[y], 1);
    } else if (opt == 1) {
      x = read();
      y = read();
      add_(S, mx + i, 1);
      query(1, 1, m, x, y, mx + i);
    } else if (opt == 2) {
      tot++;
      o[tot] = i;
      a[i].x = read();
      a[i].y = read();
      a[i].z = read();
    }
  }
  for (int i = 1; i <= m; i++) add_(pos[i], T, 1);
  for (int i = 1; i <= tot; i++) {
    add_(S, mx + o[i], 2);
    add_(mx + o[i], pos[a[o[i]].x], 1);
    add_(mx + o[i], pos[a[o[i]].y], 1);
    add_(mx + o[i], pos[a[o[i]].z], 1);
  }
  int ans = dinic();
  printf("%d\n", ans);
  for (int i = head[T]; i; i = nxt[i])
    if (w[i]) {
      int tmp = find(v[i], T);
      if (tmp) printf("%d %d\n", tmp - mx, pos_[v[i]]);
    }
  return 0;
}