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 = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3fll;
const int maxn = 20005;
const int maxm = 90005;
int getnode() {
  static int nodecnt;
  return ++nodecnt;
}
int treeNo[maxn >> 1];
int weaponNo[5005];
int enemyNo[5005];
void addedge(int u, int v, int c);
void build(int o, int l, int r) {
  treeNo[o] = getnode();
  if (o >> 1) {
    addedge(treeNo[o >> 1], treeNo[o], inf);
  }
  if (l == r) {
    enemyNo[l] = treeNo[o];
    return;
  }
  int mid = (l + r) >> 1;
  build(o << 1, l, mid);
  build(o << 1 | 1, mid + 1, r);
}
void query(int o, int l, int r, int ql, int qr, int from) {
  if (ql <= l && r <= qr) {
    addedge(from, treeNo[o], 1);
    return;
  }
  int mid = (l + r) >> 1;
  if (ql <= mid) query(o << 1, l, mid, ql, qr, from);
  if (qr > mid) query(o << 1 | 1, mid + 1, r, ql, qr, from);
}
struct Ed {
  int u, v, nx, c;
  Ed() {}
  Ed(int _u, int _v, int _nx, int _c) : u(_u), v(_v), nx(_nx), c(_c) {}
} E[maxm << 1];
int G[maxn], edtot, cur[maxn];
void addedge(int u, int v, int c) {
  E[edtot] = Ed(u, v, G[u], c);
  G[u] = edtot++;
  E[edtot] = Ed(v, u, G[v], 0);
  G[v] = edtot++;
}
int level[maxn];
int s, t;
bool bfs() {
  static int que[maxn];
  int qh(0), qt(0);
  memset(level, 0, sizeof(level));
  level[que[++qt] = s] = 1;
  while (qh != qt) {
    int x = que[++qh];
    for (int i = G[x]; i != -1; i = E[i].nx)
      if (!level[E[i].v] && E[i].c) {
        level[que[++qt] = E[i].v] = level[x] + 1;
      }
  }
  return !!level[t];
}
int dfs(int u, int rm) {
  if (u == t) return rm;
  int rm1 = rm;
  for (int &i = cur[u]; i != -1; i = E[i].nx) {
    if (level[E[i].v] == level[u] + 1 && E[i].c) {
      int flow = dfs(E[i].v, min(rm, E[i].c));
      E[i].c -= flow, E[i ^ 1].c += flow;
      if ((rm -= flow) == 0) break;
    }
  }
  if (rm1 == rm) level[u] = 0;
  return rm1 - rm;
}
int n;
int find(int x) {
  if (x >= 1 && x <= n) return x;
  for (int i = G[x]; i != -1; i = E[i].nx)
    if ((i & 1) && E[i].c) {
      E[i].c--;
      return find(E[i].v);
    }
}
int kind[5005];
int belong[5005];
vector<int> possess[5005];
vector<int> need[5005];
int main() {
  int m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) weaponNo[i] = getnode();
  memset(G, -1, sizeof(G));
  build(1, 1, m);
  s = getnode();
  t = getnode();
  for (int i = 1; i <= n; i++) {
    int op;
    scanf("%d", &op);
    if (op == 0) {
      int cnt;
      scanf("%d", &cnt);
      while (cnt--) {
        int x;
        scanf("%d", &x);
        addedge(weaponNo[i], enemyNo[x], 1);
      }
    } else if (op == 1) {
      int l, r;
      scanf("%d%d", &l, &r);
      query(1, 1, m, l, r, weaponNo[i]);
    } else {
      for (int j = 1; j <= 3; j++) {
        int x;
        scanf("%d", &x);
        addedge(weaponNo[i], enemyNo[x], 1);
        need[i].push_back(x);
      }
    }
    kind[i] = op;
  }
  for (int i = 1; i <= n; i++) {
    if (kind[i] != 2)
      addedge(s, weaponNo[i], 1);
    else
      addedge(s, weaponNo[i], 2);
  }
  for (int i = 1; i <= m; i++) addedge(enemyNo[i], t, 1);
  int ans = 0;
  while (bfs()) memcpy(cur, G, sizeof(G)), ans += dfs(s, inf);
  for (int i = 1; i <= m; i++) {
    belong[i] = find(enemyNo[i]);
    possess[belong[i]].push_back(i);
  }
  for (int i = 1; i <= n; i++) {
    if (kind[i] == 2 && possess[i].size() == 1) {
      for (int x : need[i]) {
        if (belong[x] != i) {
          possess[belong[x]].clear();
          belong[x] = i;
          possess[i].push_back(x);
          break;
        }
      }
    }
  }
  printf("%d\n", ans);
  for (int i = 1; i <= n; i++) {
    for (int x : possess[i]) {
      printf("%d %d\n", i, x);
    }
  }
  return 0;
}