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 = 20010, M = 1000010, INF = 0x3f3f3f3f;
int n, st, en;
struct edge {
  int la, b, cap;
} con[M << 1];
int tot = 1, fir[N];
void add(int from, int to, int capc) {
  con[++tot] = (edge){fir[from], to, capc};
  fir[from] = tot;
  con[++tot] = (edge){fir[to], from, 0};
  fir[to] = tot;
}
int cur[N], dis[N];
int dfs(int pos, int imp) {
  if (pos == en || (!imp)) return imp;
  int expo = 0, tmp;
  for (int &i = cur[pos]; i; i = con[i].la) {
    if (dis[con[i].b] == dis[pos] + 1) {
      tmp = dfs(con[i].b, min(imp, con[i].cap));
      con[i].cap -= tmp;
      con[i ^ 1].cap += tmp;
      expo += tmp;
      imp -= tmp;
      if (!imp) break;
    }
  }
  return expo;
}
bool bfs() {
  static queue<int> q;
  while (!q.empty()) q.pop();
  memset(dis, 0, sizeof dis);
  for (int i = 1; i <= n; ++i) cur[i] = fir[i];
  dis[st] = 1;
  q.push(st);
  for (int pos; !q.empty(); q.pop()) {
    pos = q.front();
    for (int i = fir[pos]; i; i = con[i].la) {
      if (con[i].cap && (!dis[con[i].b])) {
        dis[con[i].b] = dis[pos] + 1;
        q.push(con[i].b);
      }
    }
  }
  if (!dis[en]) return 0;
  return 1;
}
int nn, mm, vis[N], id[N << 2], ans, rec[N], sol[N], num[N];
int build(int l, int r, int x = 1) {
  if (l == r) return id[x] = l;
  id[x] = ++n;
  int mid = (l + r) >> 1;
  add(id[x], build(l, mid, x << 1), INF);
  add(id[x], build(mid + 1, r, x << 1 | 1), INF);
  return id[x];
}
void query(int l, int r, int p, int x = 1, int lp = 1, int rp = nn) {
  if (l > rp || lp > r) return;
  if (lp >= l && rp <= r) return (void)(add(p, id[x], 1));
  int mid = (lp + rp) >> 1;
  query(l, r, p, x << 1, lp, mid);
  query(l, r, p, x << 1 | 1, mid + 1, rp);
}
bool doit(int pos, int sour) {
  if (pos <= nn) {
    sol[pos] = sour;
    return 1;
  }
  for (int &i = cur[pos]; i; i = con[i].la)
    if (((i & 1) ^ 1) && con[i ^ 1].cap > 0) {
      if (doit(con[i].b, sour)) {
        con[i ^ 1].cap--;
        return 1;
      }
    }
  return 0;
}
int main() {
  int tp, x, y, z;
  scanf("%d%d", &mm, &nn);
  n = nn;
  st = ++n;
  en = ++n;
  build(1, nn);
  for (int i = 1; i <= mm; ++i) {
    scanf("%d", &tp);
    rec[++n] = i;
    switch (tp) {
      case 0:
        add(st, n, 1);
        scanf("%d", &x);
        for (int j = 1; j <= x; ++j) {
          scanf("%d", &y);
          add(n, y, 1);
        }
        break;
      case 1:
        scanf("%d%d", &x, &y);
        query(x, y, n);
        add(st, n, 1);
        break;
      case 2:
        ans += 2;
        scanf("%d%d%d", &x, &y, &z);
        vis[x] = vis[y] = vis[z] = i;
        add(x, n, 1);
        add(y, n, 1);
        add(z, n, 1);
        add(n, en, 1);
    }
  }
  for (int i = 1; i <= nn; ++i)
    if (!vis[i]) add(i, en, 1);
  while (bfs()) ans += dfs(st, INF);
  printf("%d\n", ans);
  for (int i = 1; i <= n; ++i) cur[i] = fir[i];
  for (int i = fir[st]; i; i = con[i].la)
    if ((i & 1) ^ 1) {
      if (con[i ^ 1].cap > 0) {
        doit(con[i].b, rec[con[i].b]);
      }
    }
  for (int i = 1; i <= nn; ++i)
    if ((vis[i]) && (!sol[i]) && num[vis[i]] < 2) {
      sol[i] = vis[i];
      ++num[vis[i]];
    }
  for (int i = 1; i <= nn; ++i)
    if (sol[i]) printf("%d %d\n", sol[i], i);
  return 0;
}