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 = 1e9;
int head[444444], to[444444], cap[444444], dist[444444], nxt[444444],
    cur[444444], tnode[444444], mx, ans, tp, cnp, L[444444], R[444444];
int n, m, s, t, cnt, x, y, z;
bool used[444444];
void addedge(int s, int t, int cps, int cpt) {
  cnt++;
  nxt[cnt] = head[s];
  head[s] = cnt;
  to[cnt] = t;
  cap[cnt] = cps;
  cnt++;
  nxt[cnt] = head[t];
  head[t] = cnt;
  to[cnt] = s;
  cap[cnt] = cpt;
}
void bfs() {
  memset(dist, -1, sizeof(dist));
  queue<int> q;
  q.push(s);
  dist[s] = 0;
  while (!q.empty()) {
    int x = q.front();
    q.pop();
    for (int i = head[x]; i; i = nxt[i]) {
      if (!cap[i]) continue;
      if (!~dist[to[i]]) {
        dist[to[i]] = dist[x] + 1;
        q.push(to[i]);
      }
    }
  }
}
int dfs(int i, int f) {
  if (i == t) return f;
  int tmp = f;
  for (int &j = cur[i]; j; j = nxt[j]) {
    if (!cap[j] || dist[to[j]] != dist[i] + 1) continue;
    int d = dfs(to[j], min(cap[j], f));
    if (d) {
      cap[j] -= d;
      cap[j ^ 1] += d;
      tmp -= d;
      if (!tmp) break;
    } else
      dist[to[j]] = 0;
  }
  return f - tmp;
}
int dinic() {
  int res = 0;
  while (1) {
    for (int i = 1; i <= t; i++) cur[i] = head[i];
    bfs();
    if (!~dist[t]) break;
    res += dfs(s, 1e9);
  }
  return res;
}
void build(int l, int r, int node) {
  mx = max(mx, node);
  L[node] = l;
  R[node] = r;
  if (l == r) {
    tnode[l] = node;
    return;
  }
  int mid = (l + r) >> 1;
  build(l, mid, node << 1);
  build(mid + 1, r, (node << 1) | 1);
  addedge(node, node << 1, inf, 0);
  addedge(node, (node << 1) | 1, inf, 0);
}
void update(int beg, int en, int l, int r, int node, int p) {
  if (l > en || r < beg) return;
  if (l >= beg && r <= en) {
    addedge(p, node, 1, 0);
    return;
  }
  int mid = (l + r) >> 1;
  update(beg, en, l, mid, node << 1, p);
  update(beg, en, mid + 1, r, (node << 1) | 1, p);
}
int Search(int l, int r, int node) {
  if (l == r) return l;
  int mid = (l + r) >> 1;
  for (int j = head[node]; j; j = nxt[j]) {
    if (cap[j ^ 1] &&
        ((to[j] == (node << 1)) || (to[j] == ((node << 1) | 1)))) {
      cap[j ^ 1]--;
      if (to[j] == (node << 1)) return Search(l, mid, node << 1);
      return Search(mid + 1, r, (node << 1) | 1);
    }
  }
}
int main() {
  cnt = 1;
  scanf("%d%d", &n, &m);
  build(1, m, 1);
  s = n + mx + 1;
  t = s + 1;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &tp);
    if (!tp) {
      scanf("%d", &cnp);
      for (int j = 1; j <= cnp; j++) {
        scanf("%d", &x);
        addedge(mx + i, tnode[x], 1, 0);
      }
      addedge(s, mx + i, 1, 0);
    } else if (tp == 1) {
      scanf("%d%d", &x, &y);
      update(x, y, 1, m, 1, mx + i);
      addedge(s, mx + i, 1, 0);
    } else {
      scanf("%d%d%d", &x, &y, &z);
      used[x] = used[y] = 1;
      ans += 2;
      addedge(mx + i, tnode[x], 0, 1);
      addedge(mx + i, tnode[y], 0, 1);
      addedge(mx + i, tnode[z], 1, 0);
      addedge(s, mx + i, 0, 2);
    }
  }
  for (int i = 1; i <= m; i++) {
    if (!used[i])
      addedge(tnode[i], t, 1, 0);
    else
      addedge(tnode[i], t, 0, 1);
  }
  ans += dinic();
  printf("%d\n", ans);
  for (int i = 1; i <= n; i++) {
    for (int j = head[mx + i]; j; j = nxt[j]) {
      if (!cap[j] && to[j] != s) {
        printf("%d %d\n", i, Search(L[to[j]], R[to[j]], to[j]));
      }
    }
  }
  return 0;
}