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>
const int N = 5054;
int n, R;
int count[N], from[N];
int type[N];
namespace F {
const int N = 20000, M = 6000000;
struct edge {
  int u, v, f;
  edge(int u0 = 0, int v0 = 0, int f0 = 0) : u(u0), v(v0), f(f0) {}
} e[M];
int V = 2, E = 0, si = 1, ti = 2, F;
int first[N], next[M];
int dep[N], cur[N], que[N];
inline void addedge(int u, int v, int f) {
  e[++E] = edge(u, v, f), next[E] = first[u], first[u] = E;
  e[++E] = edge(v, u), next[E] = first[v], first[v] = E;
}
bool bfs() {
  int h, t = 1, i, x, y;
  memset(dep, -1, sizeof dep);
  que[0] = si, dep[si] = 0;
  for (h = 0; h < t; h++) {
    if ((x = que[h]) == ti) return true;
    for (i = first[x]; i; i = next[i])
      if (dep[y = e[i].v] == -1 && e[i].f) que[t++] = y, dep[y] = dep[x] + 1;
  }
  return false;
}
int dfs(int x, int lim) {
  int a, c, f = 0;
  if (x == ti || !lim) return lim;
  for (int &i = cur[x]; i; i = next[i])
    if (dep[e[i].v] == dep[x] + 1 && e[i].f) {
      a = std::min(lim - f, e[i].f);
      c = dfs(e[i].v, a);
      e[i].f -= c;
      e[(((i - 1) ^ 1) + 1)].f += c;
      if ((f += c) == lim) return f;
    }
  return f;
}
int Dinic() {
  for (F = 0; bfs(); F += dfs(si, INT_MAX)) memcpy(cur, first, sizeof cur);
  return F;
}
}  // namespace F
namespace ST {
struct node {
  int v, lc, rc;
} x[N * 4];
int cnt;
int build(int L, int R) {
  if (L == R) return 2 + n + L;
  int id = ++cnt, M = (L + R - 1) >> 1;
  x[id].lc = build(L, M), x[id].rc = build(M + 1, R);
  F::addedge(id, x[id].lc, INT_MAX), F::addedge(id, x[id].rc, INT_MAX);
  return id;
}
void locate(int id, int L, int R, int ql, int qr, int v) {
  if (ql <= L && R <= qr) return F::addedge(v, id, 1);
  int M = (L + R - 1) >> 1;
  if (ql <= M) locate(x[id].lc, L, M, ql, qr, v);
  if (qr > M) locate(x[id].rc, M + 1, R, ql, qr, v);
}
}  // namespace ST
inline void link(int x, int y) { ++count[x], from[y] = x; }
int dfsA(int x, int px = 0) {
  using namespace F;
  int i, y;
  for (i = first[x]; i; i = next[i])
    if ((y = e[i].v) != px && e[(((i - 1) ^ 1) + 1)].f) {
      if (2 + n < y && y <= 2 + n + R)
        return ++e[i].f, --e[(((i - 1) ^ 1) + 1)].f, y - n - 2;
      if (x < y) return ++e[i].f, --e[(((i - 1) ^ 1) + 1)].f, dfsA(y, x);
    }
  return 0;
}
int main() {
  int i, c, u, v, w, root;
  scanf("%d%d", &n, &R);
  for (i = 1; i <= R; ++i) F::addedge(2 + n + i, 2, 1);
  ST::cnt = 2 + n + R, F::V = ST::cnt + R - 1;
  root = ST::build(1, R), assert(ST::cnt == F::V);
  for (i = 1; i <= n; ++i) {
    scanf("%d", type + i), F::addedge(1, 2 + i, type[i] + !type[i]);
    switch (type[i]) {
      case 0:
        for (scanf("%d", &c); c; --c)
          scanf("%d", &v), F::addedge(2 + i, 2 + n + v, 1);
        break;
      case 1:
        scanf("%d%d", &u, &v), ST::locate(root, 1, R, u, v, 2 + i);
        break;
      case 2:
        scanf("%d%d%d", &u, &v, &w), F::addedge(2 + i, 2 + n + u, 1),
            F::addedge(2 + i, 2 + n + v, 1), F::addedge(2 + i, 2 + n + w, 1);
        break;
    }
  }
  printf("%d\n", F::Dinic());
  for (v = 1; v <= n; ++v)
    if (type[v] == 1) {
      if ((u = dfsA(2 + v))) link(v, u);
    } else
      for (i = F::first[2 + v]; i; i = F::next[i])
        if (!F::e[i].f)
          if (u = F::e[i].v - n - 2, 0 < u && u <= R) link(v, u);
  for (v = 1; v <= n; ++v)
    if (type[v] == 2 && count[v] == 1) {
      for (i = F::first[2 + v]; i; i = F::next[i])
        if (F::e[i].f) {
          u = F::e[i].v - n - 2;
          if (0 < u && u <= R && from[u]) {
            assert(u != v);
            assert(type[from[u]] != 2);
            from[u] = v, ++count[v];
            break;
          }
        }
      assert(i);
    }
  for (v = 1; v <= n; ++v)
    if (type[v] == 2) {
      if (count[v] && count[v] != 2)
        printf("DANGER %d %d %d\n", v, type[v], count[v]);
    }
  for (i = 1; i <= R; ++i)
    if (from[i]) printf("%d %d\n", from[i], i);
  return 0;
}