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 = 5100, INF = 2e9 + 1;
int n, m, s, t, rt, cnt = 1, tot, f[N * 21], aa[N * 21], bb[N * 21], cc[N * 21],
                    z[N * 21], h[N * 21], d[N * 21], le[N * 21], ri[N * 21],
                    cur[N * 21];
struct PP {
  int nxt, to, s;
} a[N * 51];
void Add(int x, int y, int z) {
  a[++cnt].nxt = h[x];
  a[cnt].to = y;
  a[cnt].s = z;
  h[x] = cnt;
  a[++cnt].nxt = h[y];
  a[cnt].to = x;
  a[cnt].s = 0;
  h[y] = cnt;
}
int Min(int x, int y) { return x < y ? x : y; }
int Max(int x, int y) { return x > y ? x : y; }
int rd() {
  int s = 0, ff = 1;
  char w = getchar();
  while (w < '0' || w > '9') {
    if (w == '-') ff = -1;
    w = getchar();
  }
  while (w >= '0' && w <= '9') {
    s = s * 10 + (w - '0');
    w = getchar();
  }
  return s * ff;
}
int Build(int l, int r) {
  if (l == r) return n + l;
  int x = ++tot;
  int mid = (l + r) >> 1;
  le[x] = Build(l, mid);
  ri[x] = Build(mid + 1, r);
  Add(x, le[x], INF);
  Add(x, ri[x], INF);
  return x;
}
bool Bfs() {
  memset(d, 0, sizeof(d));
  memcpy(cur, h, sizeof(h));
  int l = 1, r = 1;
  z[1] = s;
  d[s] = 1;
  while (l <= r) {
    int x = z[l++];
    for (int i = h[x]; i; i = a[i].nxt) {
      int y = a[i].to;
      if (a[i].s && !d[y]) {
        d[y] = d[x] + 1;
        z[++r] = y;
      }
    }
  }
  return d[t];
}
int Dfs(int x, int ss) {
  if (x == t) return ss;
  int sum = 0;
  for (int &i = cur[x]; i; i = a[i].nxt) {
    int y = a[i].to;
    if (a[i].s && d[y] == d[x] + 1) {
      int ww = Dfs(y, Min(ss, a[i].s));
      if (ww) {
        ss -= ww;
        sum += ww;
        a[i].s -= ww;
        a[i ^ 1].s += ww;
        if (!ss) break;
      }
    }
  }
  return sum;
}
void Change(int x, int y, int l, int r, int L, int R) {
  if (L <= l && r <= R) {
    Add(y, x, 1);
    return;
  }
  int mid = (l + r) >> 1;
  if (L <= mid) Change(le[x], y, l, mid, L, R);
  if (R >= mid + 1) Change(ri[x], y, mid + 1, r, L, R);
}
int Find(int x) {
  if (x <= n) return x;
  for (int i = h[x]; i; i = a[i].nxt) {
    int y = a[i].to;
    if ((i & 1) && a[i].s) {
      a[i].s--;
      return Find(y);
    }
  }
  return 0;
}
void Dinic() {
  int ans = 0;
  while (Bfs()) ans += Dfs(s, INF + 1);
  printf("%d\n", ans);
}
void Solve() {
  for (int i = h[t]; i; i = a[i].nxt) {
    int y = a[i].to;
    if (a[i].s) f[y] = Find(y);
  }
  for (int i = 1; i <= n; i++) {
    if (aa[i]) {
      int ct = 0;
      if (f[n + aa[i]] == i) ct++;
      if (f[n + bb[i]] == i) ct++;
      if (f[n + cc[i]] == i) ct++;
      if (ct == 1) {
        if (f[n + aa[i]] != i)
          f[n + aa[i]] = i;
        else if (f[n + bb[i]] != i)
          f[n + bb[i]] = i;
      }
    }
  }
  for (int i = 1; i <= m; i++)
    if (f[n + i]) printf("%d %d\n", f[n + i], i);
}
int main() {
  n = rd();
  m = rd();
  s = n + m + 1;
  t = n + m + 2;
  tot = n + m + 2;
  rt = Build(1, m);
  for (int i = 1; i <= m; i++) Add(n + i, t, 1);
  for (int i = 1; i <= n; i++) {
    int opt = rd();
    if (opt == 0) {
      Add(s, i, 1);
      int y = rd();
      for (int j = 1; j <= y; j++) Add(i, n + rd(), 1);
    } else if (opt == 1) {
      Add(s, i, 1);
      int l = rd(), r = rd();
      Change(rt, i, 1, m, l, r);
    } else {
      Add(s, i, 2);
      aa[i] = rd();
      bb[i] = rd();
      cc[i] = rd();
      Add(i, n + aa[i], 1);
      Add(i, n + bb[i], 1);
      Add(i, n + cc[i], 1);
    }
  }
  Dinic();
  Solve();
  return 0;
}