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>
#pragma GCC optimize(3, "Ofast", "inline")
using namespace std;
int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 3) + (x << 1) + (ch ^ 48);
    ch = getchar();
  }
  return x * f;
}
struct node {
  int op, a, b, c;
} Q[5005];
int n, m, v[3000005], w[3000005], nxt[3000005], head[3000005],
    cnt = 1, cur[3000005], vis[3000005], dep[200005], S, T, Id[3000005], p,
    match[3000005];
void add(int a, int b, int c) {
  v[++cnt] = b;
  w[cnt] = c;
  nxt[cnt] = head[a];
  head[a] = cnt;
}
int dfs(int x, int limit) {
  if (x == T || !limit) return limit;
  int flow = 0, rlow = 0;
  for (int &i = cur[x]; i != -1; i = nxt[i]) {
    if (dep[v[i]] == dep[x] + 1 && w[i]) {
      if ((rlow = dfs(v[i], min(w[i], limit)))) {
        flow += rlow;
        limit -= rlow;
        w[i] -= rlow;
        w[i ^ 1] += rlow;
        if (!limit) break;
      }
    }
  }
  return flow;
}
int bfs() {
  memset(dep, 0x3f, sizeof(dep));
  for (int i = S; i <= T; i++) cur[i] = head[i];
  queue<int> q;
  q.push(S);
  dep[S] = 0;
  while (!q.empty()) {
    int c = q.front();
    q.pop();
    vis[c] = 0;
    for (int i = head[c]; i != -1; i = nxt[i]) {
      if (dep[v[i]] > dep[c] + 1 && w[i]) {
        dep[v[i]] = dep[c] + 1;
        if (!vis[v[i]]) {
          vis[v[i]] = 1;
          q.push(v[i]);
        }
      }
    }
  }
  if (dep[T] == 0x3f3f3f3f) return 0;
  return 1;
}
int Dinic() {
  int maxflow = 0;
  while (bfs()) {
    maxflow += dfs(S, 0x3f3f3f3f);
  }
  return maxflow;
}
void build(int l, int r, int k) {
  if (l == r) {
    Id[k] = l + n;
    return;
  }
  int mid = (l + r) >> 1;
  Id[k] = ++p;
  build(l, mid, k * 2);
  build(mid + 1, r, k * 2 + 1);
  add(Id[k], Id[k * 2], 0x3f3f3f3f);
  add(Id[k * 2], Id[k], 0);
  add(Id[k], Id[k * 2 + 1], 0x3f3f3f3f);
  add(Id[k * 2 + 1], Id[k], 0);
}
void modify(int l, int r, int k, int x, int y, int val) {
  if (l >= x && r <= y) {
    add(val, Id[k], 1);
    add(Id[k], val, 0);
    return;
  }
  int mid = (l + r) >> 1;
  if (x <= mid) modify(l, mid, k * 2, x, y, val);
  if (y > mid) modify(mid + 1, r, k * 2 + 1, x, y, val);
}
void find_path(int x, int &ans, int fa) {
  if (ans) return;
  if (x >= 1 && x <= n) {
    ans = x;
    return;
  }
  for (int i = head[x]; i != -1; i = nxt[i]) {
    if (v[i] != fa && w[i]) {
      w[i]--;
      find_path(v[i], ans, x);
      return;
    }
  }
}
signed main() {
  memset(head, -1, sizeof(head));
  n = read();
  m = read();
  p = n + m;
  S = 0;
  build(1, m, 1);
  T = p + 1;
  for (int i = 1; i <= n; i++) {
    Q[i].op = read();
    if (Q[i].op == 0) {
      int siz = read();
      while (siz--) {
        int x = read();
        add(i, x + n, 1);
        add(x + n, i, 0);
      }
    }
    if (Q[i].op == 1) {
      int x = read(), y = read();
      modify(1, m, 1, x, y, i);
    }
    if (Q[i].op == 2) {
      Q[i].a = read();
      Q[i].b = read();
      Q[i].c = read();
      add(i, Q[i].a + n, 1);
      add(Q[i].a + n, i, 0);
      add(i, Q[i].b + n, 1);
      add(Q[i].b + n, i, 0);
      add(i, Q[i].c + n, 1);
      add(Q[i].c + n, i, 0);
    }
  }
  for (int i = 1; i <= n; i++) {
    if (Q[i].op != 2)
      add(S, i, 1), add(i, S, 0);
    else
      add(S, i, 2), add(i, S, 0);
  }
  for (int i = 1; i <= m; i++) add(i + n, T, 1), add(T, i + n, 0);
  int ans = Dinic();
  printf("%d\n", ans);
  for (int i = head[T]; i != -1; i = nxt[i]) {
    if (w[i]) {
      find_path(v[i], match[v[i]], T);
    }
  }
  for (int i = 1; i <= n; i++) {
    if (Q[i].op == 2) {
      int sum = 0;
      sum += (match[Q[i].a + n] == i);
      sum += (match[Q[i].b + n] == i);
      sum += (match[Q[i].c + n] == i);
      if (sum == 1) {
        if (match[Q[i].a + n] != i) {
          match[Q[i].a + n] = i;
          continue;
        }
        if (match[Q[i].b + n] != i) {
          match[Q[i].b + n] = i;
          continue;
        }
        if (match[Q[i].c + n] != i) {
          match[Q[i].c + n] = i;
          continue;
        }
      }
    }
  }
  for (int i = n + 1; i <= n + m; i++) {
    if (match[i]) printf("%d %d\n", match[i], i - n);
  }
}