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 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 * 10 + c - '0';
    c = getchar();
  }
  return x * f;
}
int n, m, head[5005 * 5], level[5005 * 5],
    cnt = 0, max_idx = 0, s, t, pos[5005], wp_num[5005 * 5], jud_num[5005 * 5];
int ship[5005][3], res[5005], omg_cnt[5005];
struct Node1 {
  int l, r;
} T[5005 * 4];
struct Node2 {
  int nxt, to, cap;
} Edges[5005 * 400];
void addedge(int u, int v, int c) {
  Edges[cnt].nxt = head[u];
  head[u] = cnt;
  Edges[cnt].to = v, Edges[cnt++].cap = c;
}
void insert(int u, int v, int c) {
  addedge(u, v, c);
  addedge(v, u, 0);
}
bool bfs() {
  memset(level, -1, sizeof(level));
  queue<int> q;
  q.push(s), level[s] = 0;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int i = head[u]; ~i; i = Edges[i].nxt) {
      int v = Edges[i].to;
      if (level[v] == -1 && Edges[i].cap) level[v] = level[u] + 1, q.push(v);
    }
  }
  if (level[t] == -1) return false;
  return true;
}
int dfs(int u, int flow) {
  int f = 0, d = 0;
  if (u == t) return flow;
  for (int i = head[u]; ~i && flow > f; i = Edges[i].nxt) {
    int v = Edges[i].to;
    if (level[v] == level[u] + 1 && Edges[i].cap) {
      d = dfs(v, min(flow - f, Edges[i].cap));
      f += d;
      Edges[i].cap -= d;
      Edges[i ^ 1].cap += d;
    }
  }
  if (!f) level[u] = -1;
  return f;
}
void build(int idx, int l, int r) {
  max_idx = max(max_idx, idx), T[idx].l = l, T[idx].r = r;
  if (l == r) {
    pos[l] = idx;
    jud_num[l] = cnt;
    insert(idx, t, 1);
    return;
  }
  int mid = (l + r) >> 1;
  build(idx << 1, l, mid), build(idx << 1 | 1, mid + 1, r);
  insert(idx, idx << 1, 0x3f3f3f3f), insert(idx, idx << 1 | 1, 0x3f3f3f3f);
}
void add(int idx, int l, int r, int wp) {
  if (l <= T[idx].l && r >= T[idx].r) {
    insert(wp, idx, 1);
    return;
  }
  int mid = (T[idx].l + T[idx].r) >> 1;
  if (l > mid)
    add(idx << 1 | 1, l, r, wp);
  else if (r <= mid)
    add(idx << 1, l, r, wp);
  else
    add(idx << 1 | 1, l, r, wp), add(idx << 1, l, r, wp);
}
int main() {
  memset(head, -1, sizeof(head));
  n = read(), m = read();
  t = 0, build(1, 1, m), s = ++max_idx;
  for (int i = 1; i <= n; i++) {
    int typ = read();
    wp_num[max_idx + 1] = i;
    if (typ == 0) {
      insert(s, ++max_idx, 1);
      int k = read();
      for (int j = 1; j <= k; j++) {
        int x = read();
        insert(max_idx, pos[x], 1);
      }
    } else if (typ == 1) {
      insert(s, ++max_idx, 1);
      int l = read(), r = read();
      add(1, l, r, max_idx);
    } else {
      insert(s, ++max_idx, 2);
      ship[i][0] = read(), ship[i][1] = read(), ship[i][2] = read();
      insert(max_idx, pos[ship[i][0]], 1);
      insert(max_idx, pos[ship[i][1]], 1);
      insert(max_idx, pos[ship[i][2]], 1);
    }
  }
  int ans = 0, d;
  while (bfs()) {
    while (d = dfs(s, 0x3f3f3f3f)) ans += d;
  }
  printf("%d\n", ans);
  for (int i = 1; i <= m; i++) {
    if (!Edges[jud_num[i]].cap) {
      int p = pos[i];
      while (!wp_num[p]) {
        for (int j = head[p]; ~j; j = Edges[j].nxt) {
          if (j & 1 == 0) continue;
          if (Edges[j].cap) {
            Edges[j].cap--;
            p = Edges[j].to;
            break;
          }
        }
      }
      res[i] = wp_num[p];
      omg_cnt[wp_num[p]]++;
    }
  }
  for (int i = 1; i <= n; i++)
    if (ship[i][0] && omg_cnt[i] == 1) {
      if (res[ship[i][0]] != i)
        res[ship[i][0]] = i;
      else if (res[ship[i][1]] != i)
        res[ship[i][1]] = i;
      else if (res[ship[i][2]] != i)
        res[ship[i][2]] = i;
    }
  for (int i = 1; i <= m; i++)
    if (res[i]) printf("%d %d\n", res[i], i);
  return 0;
}