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;
struct Edge {
  long long l;
  int e, n;
} e[200010 << 1];
int hd[200010], cur[200010], cnt = 1;
void add(int a, int b, long long l) {
  e[++cnt].e = b;
  e[cnt].l = l;
  e[cnt].n = hd[a];
  hd[a] = cnt;
  e[++cnt].e = a;
  e[cnt].l = 0;
  e[cnt].n = hd[b];
  hd[b] = cnt;
}
long long inf = 1e15;
int n, m, s, t;
long long a[200010];
int dep[200010];
queue<int> Q;
long long dfs(int p, long long flow) {
  if (p == t) return flow;
  int i;
  for (i = cur[p]; i; i = e[i].n) {
    int q = e[i].e;
    cur[p] = i;
    if (dep[q] == dep[p] + 1 && e[i].l) {
      long long ans = dfs(q, min(flow, e[i].l));
      if (ans) {
        e[i].l -= ans;
        e[i ^ 1].l += ans;
        return ans;
      }
    }
  }
  return 0;
}
int bfs() {
  memset(dep, 0, sizeof(dep));
  Q.push(s);
  dep[s] = 1;
  int i;
  while (!Q.empty()) {
    int p = Q.front();
    Q.pop();
    for (i = hd[p]; i; i = e[i].n) {
      int q = e[i].e;
      if (!dep[q] && e[i].l) dep[q] = dep[p] + 1, Q.push(q);
    }
  }
  return dep[t];
}
int tot;
long long dinic() {
  int i;
  long long d, ans = 0;
  while (bfs()) {
    for (i = 0; i <= tot; i++) cur[i] = hd[i];
    while ((d = dfs(s, inf))) ans += d;
  }
  return ans;
}
int id[200010], L[200010], R[200010];
void build(int p, int l, int r) {
  id[p] = ++tot;
  L[p] = l;
  R[p] = r;
  if (l == r) {
    add(tot, l, 1);
    return;
  }
  build(p << 1, l, (l + r) >> 1);
  build(p << 1 | 1, ((l + r) >> 1) + 1, r);
  add(id[p], id[p << 1], inf);
  add(id[p], id[p << 1 | 1], inf);
}
void upd(int p, int l, int r) {
  if (L[p] >= l && R[p] <= r) {
    add(tot, id[p], 1);
    return;
  }
  if (L[p] > r || R[p] < l) return;
  upd(p << 1, l, r);
  upd(p << 1 | 1, l, r);
}
map<int, int> mp[200010];
int vis[200010], start, ret;
void solve(int x) {
  if (x >= start) {
    ret = x - start;
    return;
  }
  map<int, int>::iterator it = mp[x].begin();
  solve(it->first);
  --it->second;
  if (!it->second) mp[x].erase(it);
}
int main() {
  int i, j, u, k, l, r, opt;
  int temp = 0;
  scanf("%d%d", &n, &m);
  tot = m;
  build(1, 1, m);
  s = ++tot;
  t = ++tot;
  start = tot;
  for (i = 1; i <= n; i++) {
    ++tot;
    scanf("%d", &opt);
    if (opt == 0) {
      add(s, tot, 1);
      scanf("%d", &k);
      while (k--) scanf("%d", &u), add(tot, u, 1);
    } else if (opt == 1) {
      add(s, tot, 1);
      scanf("%d%d", &l, &r);
      upd(1, l, r);
    } else {
      int A, B, C;
      scanf("%d%d%d", &A, &B, &C);
      add(tot, A, 1);
      add(tot, B, 0);
      e[cnt].l = 1;
      vis[B] = 1;
      add(tot, C, 1);
      e[cnt].l = 1;
      vis[C] = 1;
      temp += 2;
    }
  }
  for (i = 1; i <= m; i++)
    if (!vis[i]) add(i, t, 1);
  printf("%I64d\n", dinic() + temp);
  for (i = 1; i <= tot; i++)
    for (j = hd[i]; j; j = e[j].n)
      if ((j & 1) && e[j].l) mp[i][e[j].e] = e[j].l;
  for (i = 1; i <= m; i++) {
    int flag = 0;
    for (j = hd[i]; j; j = e[j].n)
      if (e[j].e == t && e[j].l) {
        flag = 1;
        break;
      }
    if (flag) continue;
    solve(i);
    printf("%d %d\n", ret, i);
  }
  return 0;
}