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 = 4e4 + 10;
const int M = 2e6 + 10;
struct bian {
  long long from, to, w, tag;
} eg[M << 1];
long long front[N], num;
void add(long long x, long long y, long long w) {
  eg[++num].to = y;
  eg[num].from = front[x];
  front[x] = num;
  eg[num].w = w;
  eg[num].tag = 1;
  swap(x, y);
  eg[++num].to = y;
  eg[num].from = front[x];
  front[x] = num;
}
long long s, t;
long long _front[N], dis[N];
bool bfs() {
  queue<int> q;
  q.push(s);
  memset(dis, 0, sizeof(dis));
  dis[s] = 1;
  while (!q.empty()) {
    long long o = q.front();
    q.pop();
    for (long long i = front[o]; i; i = eg[i].from) {
      long long to = eg[i].to;
      if (dis[to] == 0 && eg[i].w) {
        dis[to] = dis[o] + 1;
        q.push(to);
      }
    }
  }
  return dis[t] != 0;
}
long long dfs(int o, long long lim) {
  if (o == t) return lim;
  long long mins = 0;
  for (long long &i = _front[o]; i; i = eg[i].from) {
    long long to = eg[i].to;
    if (eg[i].w == 0 || dis[to] != dis[o] + 1) continue;
    long long now = dfs(to, min(lim - mins, eg[i].w));
    if (now) {
      eg[i].w -= now;
      eg[((i - 1) ^ 1) + 1].w += now;
      mins += now;
      if (mins == lim) break;
    }
  }
  return mins;
}
long long dinic() {
  long long re = 0;
  while (bfs()) {
    memcpy(_front, front, sizeof(front));
    re += dfs(s, 2e9);
  }
  return re;
}
int n, m;
int tot;
void build1(int o, int l, int r) {
  tot = max(tot, o);
  if (l == r) return;
  add(o, o << 1, 1e9);
  add(o, o << 1 | 1, 1e9);
  int mid = (l + r) >> 1;
  build1(o << 1, l, mid);
  build1(o << 1 | 1, mid + 1, r);
}
void build2(int o, int l, int r) {
  if (l == r) {
    add(o, tot + l, 1);
    return;
  }
  int mid = (l + r) >> 1;
  build2(o << 1, l, mid);
  build2(o << 1 | 1, mid + 1, r);
}
void adds(int o, int l, int r, int L, int R, int now) {
  if (L <= l && r <= R) {
    add(now, o, 1);
    return;
  }
  int mid = (l + r) >> 1;
  if (mid >= L) adds(o << 1, l, mid, L, R, now);
  if (mid < R) adds(o << 1 | 1, mid + 1, r, L, R, now);
}
int dy[N], has[N];
int find(int o) {
  if (o > tot + m && o <= tot + m + n) return o - tot - m;
  for (int i = front[o]; i; i = eg[i].from) {
    int to = eg[i].to;
    if (eg[i].tag == 1 || eg[i].w == 0) continue;
    --eg[i].w;
    return find(to);
  }
  return 0;
}
int OMG[N][4];
int main() {
  scanf("%d%d", &n, &m);
  build1(1, 1, m);
  build2(1, 1, m);
  s = tot + n + m + 1;
  t = s + 1;
  for (int i = 1; i <= m; ++i) add(i + tot, t, 1);
  for (int i = 1; i <= n; ++i) {
    int op;
    scanf("%d", &op);
    if (op == 0) {
      add(s, tot + m + i, 1);
      int k;
      scanf("%d", &k);
      while (k--) {
        int now;
        scanf("%d", &now);
        add(tot + m + i, tot + now, 1);
      }
    }
    if (op == 1) {
      add(s, tot + m + i, 1);
      int l, r;
      scanf("%d%d", &l, &r);
      adds(1, 1, m, l, r, tot + m + i);
    }
    if (op == 2) {
      OMG[i][0] = 1;
      add(s, tot + m + i, 2);
      int a, b, c;
      scanf("%d%d%d", &a, &b, &c);
      OMG[i][1] = a;
      OMG[i][2] = b;
      OMG[i][3] = c;
      add(tot + m + i, tot + a, 1);
      add(tot + m + i, tot + b, 1);
      add(tot + m + i, tot + c, 1);
    }
  }
  printf("%d\n", dinic());
  for (int i = 1; i <= m; ++i) {
    dy[i] = find(i + tot);
    ++has[dy[i]];
  }
  for (int i = 1; i <= n; ++i) {
    if (OMG[i][0] == 1 && has[i] == 1) {
      if (dy[OMG[i][1]] != i)
        dy[OMG[i][1]] = i;
      else
        dy[OMG[i][2]] = i;
    }
  }
  for (int i = 1; i <= m; ++i) {
    if (dy[i]) printf("%d %d\n", dy[i], i);
  }
}