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 double eps = 1e-8;
const double PI = acos(-1.0);
const int MAXN = 2e5 + 5;
const int MAXM = 2e6 + 5;
const int MOD = 1e9 + 7;
int sgn(double x) {
  if (fabs(x) < eps) return 0;
  if (x < 0)
    return -1;
  else
    return 1;
}
long long pw(long long a, long long n, long long mod) {
  long long ret = 1;
  while (n) {
    if (n & 1) ret = ret * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return ret;
}
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
void inc(long long &a, long long b) {
  a += b;
  if (a >= MOD) a -= MOD;
}
void dec(long long &a, long long b) {
  a -= b;
  if (a < 0) a += MOD;
}
int mul(int a, int b) {
  long long c = 1ll * a * b;
  return c - c / MOD * MOD;
}
int n, m, tot, head[MAXN];
struct Edge {
  int to, w, nxt;
} edge[MAXM];
void init() {
  tot = 0;
  memset(head, -1, sizeof(head));
}
void addedge(int u, int v, int w) {
  edge[tot].to = v;
  edge[tot].w = w;
  edge[tot].nxt = head[u];
  head[u] = tot++;
  edge[tot].to = u;
  edge[tot].w = 0;
  edge[tot].nxt = head[v];
  head[v] = tot++;
}
int st, ed, d[MAXN], cur[MAXN];
int bfs() {
  queue<int> Q;
  for (int i = st; i < ed + 1; i++) d[i] = 0;
  Q.push(st);
  d[st] = 1;
  while (!Q.empty()) {
    int x = Q.front();
    Q.pop();
    for (int i = head[x]; i != -1; i = edge[i].nxt) {
      int v = edge[i].to;
      if (!d[v] && edge[i].w) {
        d[v] = d[x] + 1;
        Q.push(v);
      }
    }
  }
  return d[ed];
}
int dfs(int x, int w) {
  if (x == ed || w == 0) return w;
  int f, ret = 0;
  for (int &i = cur[x]; i != -1; i = edge[i].nxt) {
    int v = edge[i].to;
    if (d[v] == d[x] + 1 && (f = dfs(v, min(w, edge[i].w)))) {
      edge[i].w -= f;
      edge[i ^ 1].w += f;
      ret += f;
      w -= f;
      if (!w) break;
    }
  }
  return ret;
}
int Dinic() {
  int flow = 0;
  while (bfs()) {
    for (int i = st; i < ed + 1; i++) cur[i] = head[i];
    flow += dfs(st, INF);
  }
  return flow;
}
int sz, id[MAXN << 2];
void build(int l, int r, int rt) {
  if (l == r) {
    id[rt] = l;
    return;
  }
  id[rt] = ++sz;
  int mid = l + r >> 1;
  build(l, mid, rt << 1);
  build(mid + 1, r, rt << 1 | 1);
  addedge(id[rt], id[rt << 1], INF);
  addedge(id[rt], id[rt << 1 | 1], INF);
}
void upd(int i, int L, int R, int l, int r, int rt) {
  if (L <= l && r <= R) {
    addedge(sz + i, id[rt], 1);
    return;
  }
  int mid = l + r >> 1;
  if (L <= mid) upd(i, L, R, l, mid, rt << 1);
  if (R > mid) upd(i, L, R, mid + 1, r, rt << 1 | 1);
}
int res, barn[MAXN];
void find(int u, int weap) {
  if (u == ed) return;
  for (int i = head[u]; i != -1; i = edge[i].nxt) {
    int v = edge[i].to;
    if (!(i & 1) && edge[i ^ 1].w && res) {
      find(v, weap);
      edge[i].w++;
      edge[i ^ 1].w--;
      if (v == ed) {
        barn[u] = weap;
        res--;
      }
    }
  }
}
int A[MAXN], B[MAXN], C[MAXN], sum[MAXN];
int main() {
  scanf("%d%d", &n, &m);
  init();
  sz = m;
  build(1, m, 1);
  st = 0, ed = sz + n + 1;
  int ty, k, x, l, r;
  for (int i = 1; i < n + 1; i++) {
    scanf("%d", &ty);
    if (ty == 0) {
      scanf("%d", &k);
      for (int j = 0; j < k; j++) scanf("%d", &x), addedge(sz + i, x, 1);
    } else if (ty == 1) {
      scanf("%d%d", &l, &r), upd(i, l, r, 1, m, 1);
    } else {
      scanf("%d%d%d", &A[i], &B[i], &C[i]);
      addedge(sz + i, A[i], 1);
      addedge(sz + i, B[i], 1);
      addedge(sz + i, C[i], 1);
    }
  }
  for (int i = 1; i < n + 1; i++) addedge(st, sz + i, A[i] ? 2 : 1);
  for (int i = 1; i < m + 1; i++) addedge(i, ed, 1);
  printf("%d\n", Dinic());
  for (int i = head[st]; i != -1; i = edge[i].nxt) {
    int v = edge[i].to;
    if (edge[i ^ 1].w) res = edge[i ^ 1].w, find(v, v - sz);
  }
  for (int i = 1; i < m + 1; i++) sum[barn[i]]++;
  for (int i = 1; i < n + 1; i++) {
    if (A[i] && sum[i] == 1) {
      if (barn[A[i]] && barn[A[i]] != i)
        barn[A[i]] = i;
      else if (barn[B[i]] && barn[B[i]] != i)
        barn[B[i]] = i;
      else
        barn[C[i]] = i;
    }
  }
  for (int i = 1; i < m + 1; i++)
    if (barn[i]) printf("%d %d\n", barn[i], i);
}