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;
int n, m, ecnt, p[5050][3], vis[5050], ans, cont[5050], s, t, ok[5050],
    q[5050 << 5], level[5050 << 4];
struct node {
  int v, c, k;
  node *next, *rev;
} pool[3000000], *h[5050 << 4], *cur[5050 << 4];
inline void adde(int u, int v, int c) {
  node *p = &pool[ecnt++], *q = &pool[ecnt++];
  *p = node{v, c, 1, h[u], q}, h[u] = p;
  *q = node{u, 0, 0, h[v], p}, h[v] = q;
}
void build(int u, int l, int r) {
  t = max(u + n + m + 1, t);
  if (l == r) return adde(u + n + m, l + m, (1 << 20));
  int mid = (l + r) >> 1;
  build(u << 1, l, mid), build(u << 1 | 1, mid + 1, r);
  adde(u + n + m, (u << 1) + n + m, (1 << 20)),
      adde(u + n + m, (u << 1 | 1) + n + m, (1 << 20));
}
void change(int u, int l, int r, int tl, int tr, int x) {
  if (tl <= l && r <= tr) return adde(x, u + n + m, (1 << 20));
  int mid = (l + r) >> 1;
  if (tl <= mid) change(u << 1, l, mid, tl, tr, x);
  if (mid < tr) change(u << 1 | 1, mid + 1, r, tl, tr, x);
}
bool bfs() {
  int front = 0, rear = 1;
  memset(level, 0, sizeof(level)), level[s] = 1, q[0] = s;
  while (front < rear) {
    int u = q[front++];
    for (node *p = h[u]; p; p = p->next) {
      if (p->c && !level[p->v]) {
        level[p->v] = level[u] + 1;
        q[rear++] = p->v;
        if (p->v == t) return 1;
      }
    }
  }
  return 0;
}
int dfs(int u, int f) {
  if (u == t) return f;
  int F, flow = 0;
  for (node *&p = cur[u]; p; p = p->next) {
    if (p->c && level[p->v] == level[u] + 1) {
      F = dfs(p->v, min(f - flow, p->c));
      flow += F, p->c -= F, p->rev->c += F;
      if (flow == f) return flow;
    }
  }
  return flow;
}
int Dinic() {
  int ret = 0;
  while (bfs()) {
    for (register int i = s; i <= t; ++i) cur[i] = h[i];
    ret += dfs(s, (1 << 20));
  }
  return ret;
}
int search(int u) {
  if (m + 1 <= u && u <= m + n) return u;
  for (node *p = h[u]; p; p = p->next) {
    if (p->k && p->c != (1 << 20)) {
      ++p->c;
      return search(p->v);
    }
  }
}
int main() {
  int op, l, r, k;
  scanf("%d%d", &m, &n);
  build(1, 1, n);
  for (register int i = 1; i <= m; ++i) {
    scanf("%d", &op);
    if (op == 0) {
      adde(s, i, 1);
      scanf("%d", &k);
      while (k--) scanf("%d", &l), change(1, 1, n, l, l, i);
    } else if (op == 1) {
      adde(s, i, 1);
      scanf("%d%d", &l, &r);
      change(1, 1, n, l, r, i);
    } else {
      adde(i, t, 1);
      scanf("%d%d%d", &l, &r, &k);
      cont[l] = cont[r] = cont[k] = i, ans += 2;
      p[i][0] = l, p[i][1] = r, p[i][2] = k;
    }
  }
  for (register int i = 1; i <= n; ++i)
    if (!cont[i])
      adde(i + m, t, 1);
    else
      adde(i + m, cont[i], 1);
  ans += Dinic();
  for (node *q = h[s]; q; q = q->next)
    if (!q->c) ok[q->v] = 1;
  printf("%d\n", ans);
  for (register int i = 1; i <= m; ++i) {
    if (!p[i][0] && ok[i]) {
      int target = search(i);
      printf("%d %d\n", i, target - m);
      vis[target - m] = 1;
    }
  }
  for (register int i = 1; i <= m; ++i) {
    if (p[i][0]) {
      if (!vis[p[i][0]]) printf("%d %d\n", i, p[i][0]);
      if (!vis[p[i][1]]) printf("%d %d\n", i, p[i][1]);
      if (vis[p[i][0]] || vis[p[i][1]]) printf("%d %d\n", i, p[i][2]);
    }
  }
  return 0;
}