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 = 2e6 + 5;
const int M = 5e3 + 5;
const int INF = INT_MAX;
const int Meet_point = 35000;
int tot = 1, cnt[N], n, m, head[N], dep[N], ncnt, ite[N];
queue<int> q;
struct Edge {
  int to, nxt, cap;
} e[N];
int ans[N];
struct Weapons {
  int type, l, r, siz, a, b, c;
} wea[M];
int tree[N];
int read() {
  int x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = (x << 1) + (x << 3) + (c ^ 48);
    c = getchar();
  }
  return x * f;
}
void addedge(int u, int v, int cap) {
  e[++tot] = (Edge){v, head[u], cap};
  head[u] = tot;
  e[++tot] = (Edge){u, head[v], 0};
  head[v] = tot;
}
void BuildTree(int u, int l, int r) {
  if (l == r) {
    tree[u] = l;
    return;
  }
  tree[u] = ++ncnt;
  int mid = (l + r) >> 1;
  BuildTree(u * 2, l, mid);
  BuildTree(u * 2 + 1, mid + 1, r);
  addedge(tree[u], tree[u * 2], INF);
  addedge(tree[u], tree[u * 2 + 1], INF);
}
void Modify(int l, int r, int u, int id, int &L, int &R) {
  if (L <= l && r <= R) {
    addedge(id, tree[u], 1);
    return;
  }
  int mid = (l + r) >> 1;
  if (L <= mid) Modify(l, mid, u * 2, id, L, R);
  if (R > mid) Modify(mid + 1, r, u * 2 + 1, id, L, R);
}
void BFS() {
  dep[0] = 1;
  q.push(0);
  while (!q.empty()) {
    int x = q.front();
    q.pop();
    for (int i = head[x]; i; i = e[i].nxt) {
      int y = e[i].to;
      if (e[i].cap && !dep[y]) {
        dep[y] = dep[x] + 1;
        q.push(y);
      }
    }
  }
}
int DFS(int u, int fl) {
  if (!fl || u == Meet_point) return fl;
  for (int &i = ite[u]; i; i = e[i].nxt) {
    int x = e[i].to;
    if (e[i].cap && dep[u] < dep[x]) {
      int tmp = DFS(x, min(fl, e[i].cap));
      if (tmp) {
        e[i].cap -= tmp;
        e[i ^ 1].cap += tmp;
        return tmp;
      }
    }
  }
  return 0;
}
int Dinic() {
  for (int f, flow = 0;;) {
    memset(dep, 0, sizeof(dep));
    BFS();
    if (!dep[Meet_point]) return flow;
    memcpy(ite, head, sizeof(ite));
    while (f = DFS(0, INF)) flow += f;
  }
}
void Find_Route(int cur, int &s, int pre) {
  if (s) return;
  if (cur > m && cur <= n + m) {
    s = cur - m;
    return;
  }
  for (int i = head[cur]; i; i = e[i].nxt) {
    if (e[i].to != pre && e[i].cap) {
      Find_Route(e[i].to, s, cur);
      --e[i].cap;
      return;
    }
  }
}
int main() {
  n = read(), m = read();
  ncnt = n + m;
  BuildTree(1, 1, m);
  for (int i = 1; i <= n; i++) {
    wea[i].type = read();
    if (wea[i].type == 0) {
      wea[i].siz = read();
      addedge(0, i + m, 1);
      for (int j = 1; j <= wea[i].siz; j++) {
        int x = read();
        addedge(i + m, x, 1);
      }
    } else if (wea[i].type == 1) {
      addedge(0, i + m, 1);
      wea[i].l = read(), wea[i].r = read();
      Modify(1, m, 1, i + m, wea[i].l, wea[i].r);
    } else {
      addedge(0, i + m, 2);
      wea[i].a = read();
      wea[i].b = read();
      wea[i].c = read();
      addedge(i + m, wea[i].a, 1);
      addedge(i + m, wea[i].b, 1);
      addedge(i + m, wea[i].c, 1);
    }
  }
  for (int i = 1; i <= m; i++) addedge(i, Meet_point, 1);
  int Max_Flow = Dinic();
  cout << Max_Flow << endl;
  for (int i = head[Meet_point]; i; i = e[i].nxt) {
    Find_Route(e[i].to, ans[e[i].to], Meet_point);
  }
  for (int i = 1; i <= m; i++) ++cnt[ans[i]];
  for (int i = 1; i <= n; i++) {
    if (wea[i].type == 2 && cnt[i] == 1) {
      if (ans[wea[i].a] != i)
        ans[wea[i].a] = i;
      else
        ans[wea[i].b] = i;
    }
  }
  for (int i = 1; i <= m; i++)
    if (ans[i]) printf("%d %d\n", ans[i], i);
  return 0;
}