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 = 30010;
const int M = 1e5 + 10;
const int INF = 0x3f3f3f3f;
vector<int> V[N], G[N];
int head[N], cnt = 1, dis[N], t, s, id[N << 1], tot, n, m, op[N / 3],
             res[N / 3], cur[N];
struct edge {
  int next, to, w;
} e[M * 20];
void add(int u, int v, int w) {
  e[++cnt].next = head[u];
  e[cnt].to = v;
  e[cnt].w = w;
  head[u] = cnt;
}
void add_edge(int u, int v, int w) {
  add(u, v, w);
  add(v, u, 0);
}
bool bfs() {
  for (int i = 1; i <= t; i++) dis[i] = -1;
  queue<int> q;
  q.push(s);
  dis[s] = 0;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int i = head[u]; i; i = e[i].next) {
      int v = e[i].to;
      if (e[i].w && dis[v] == -1) {
        dis[v] = dis[u] + 1;
        q.push(v);
        if (v == t) return true;
      }
    }
  }
  return dis[t] != -1;
}
int dfs(int u, int flo) {
  if (u == t || !flo) return flo;
  int detla = flo;
  for (int i = cur[u]; i && detla; i = e[i].next) {
    cur[u] = i;
    int v = e[i].to;
    if (e[i].w && dis[v] == dis[u] + 1) {
      int d = dfs(v, min(detla, e[i].w));
      e[i].w -= d, e[i ^ 1].w += d;
      detla -= d;
    }
  }
  return flo - detla;
}
void dini() {
  int ans = 0;
  while (bfs()) {
    for (int i = 1; i <= t; i++) cur[i] = head[i];
    ans += dfs(s, INF);
  }
  printf("%d\n", ans);
}
void build(int l, int r, int rt) {
  if (l == r)
    id[rt] = l + n;
  else
    id[rt] = ++tot;
  if (l == r) return;
  int mid = l + r >> 1;
  build(l, mid, (rt << 1));
  build(mid + 1, r, (rt << 1 | 1));
  add_edge(id[rt], id[(rt << 1)], INF);
  add_edge(id[rt], id[(rt << 1 | 1)], INF);
}
void query(int l, int r, int L, int R, int rt, int u) {
  if (L <= l && r <= R) {
    add_edge(u, id[rt], 1);
    return;
  }
  int mid = l + r >> 1;
  if (L <= mid) query(l, mid, L, R, (rt << 1), u);
  if (mid < R) query(mid + 1, r, L, R, (rt << 1 | 1), u);
}
int _find(int u, int pre) {
  if (u <= n) return u;
  for (int i = head[u]; i; i = e[i].next) {
    int v = e[i].to, w = e[i].w;
    if (w >= 1 && w <= 10000 && v != pre) {
      e[i].w--;
      return _find(v, u);
    }
  }
}
int main() {
  scanf("%d %d", &n, &m);
  tot = n + m;
  build(1, m, 1);
  s = ++tot, t = ++tot;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &op[i]);
    if (op[i] == 0) {
      int k;
      scanf("%d", &k);
      while (k--) {
        int x;
        scanf("%d", &x);
        add_edge(i, n + x, 1);
      }
    } else if (op[i] == 1) {
      int l, r;
      scanf("%d %d", &l, &r);
      query(1, m, l, r, 1, i);
    } else {
      int a, b, c;
      scanf("%d %d %d", &a, &b, &c);
      add_edge(i, n + a, 1);
      add_edge(i, n + b, 1);
      add_edge(i, n + c, 1);
      G[i].push_back(a);
      G[i].push_back(b);
      G[i].push_back(c);
    }
  }
  for (int i = 1; i <= n; i++) add_edge(s, i, op[i] == 2 ? 2 : 1);
  for (int i = 1; i <= m; i++) add_edge(i + n, t, 1);
  dini();
  for (int i = head[t]; i; i = e[i].next) {
    int v = e[i].to, w = e[i].w;
    if (w >= 1) {
      res[v - n] = _find(v, t);
      V[res[v - n]].push_back(v - n);
    }
  }
  for (int i = 1; i <= n; i++) {
    if (op[i] == 2 && V[i].size() == 1) {
      for (auto it : G[i]) {
        if (res[it] != i) {
          res[it] = i;
          break;
        }
      }
    }
  }
  for (int i = 1; i <= m; i++) {
    if (res[i]) printf("%d %d\n", res[i], i);
  }
  return 0;
}