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 maxn = 400010;
const int mod = 1e9 + 7;
const int MAX = 1000000010;
const double eps = 1e-6;
const double PI = acos(-1);
template <typename T>
inline void read(T &x) {
  x = 0;
  T f = 1;
  char ch;
  do {
    ch = getchar();
    if (ch == '-') f = -1;
  } while (ch < '0' || ch > '9');
  do x = x * 10 + ch - '0', ch = getchar();
  while (ch <= '9' && ch >= '0');
  x *= f;
}
template <typename A, typename B>
inline void read(A &x, B &y) {
  read(x);
  read(y);
}
template <typename A, typename B, typename C>
inline void read(A &x, B &y, C &z) {
  read(x);
  read(y);
  read(z);
}
template <typename A, typename B, typename C, typename D>
inline void read(A &x, B &y, C &z, D &w) {
  read(x);
  read(y);
  read(z);
  read(w);
}
template <typename A, typename B>
inline A fexp(A x, B p) {
  A ans = 1;
  for (; p; p >>= 1, x = 1LL * x * x % mod)
    if (p & 1) ans = 1LL * ans * x % mod;
  return ans;
}
template <typename A, typename B>
inline A fexp(A x, B p, A mo) {
  A ans = 1;
  for (; p; p >>= 1, x = 1LL * x * x % mo)
    if (p & 1) ans = 1LL * ans * x % mo;
  return ans;
}
int n, m, N;
int ID[5010], XX[5050], YY[5050], ZZ[5050];
int Is[5010];
struct Node {
  int l, r, id;
} T[5010 << 2];
struct Edge {
  int to, cap;
  Edge *oppo, *next;
};
Edge *E[maxn], Pr[maxn << 2];
int cnt = 0;
void addedge(int u, int v, int cap) {
  Pr[++cnt].to = v;
  Pr[cnt].cap = cap;
  Pr[cnt].oppo = &Pr[cnt + 1];
  Pr[cnt].next = E[u];
  E[u] = &Pr[cnt];
  Pr[++cnt].to = u;
  Pr[cnt].cap = 0;
  Pr[cnt].oppo = &Pr[cnt - 1];
  Pr[cnt].next = E[v];
  E[v] = &Pr[cnt];
}
int H[maxn];
int s, t;
bool Makelevel() {
  memset(H, 127, sizeof(H));
  H[s] = 0;
  static queue<int> Q;
  Q.push(s);
  while (!Q.empty()) {
    int u = Q.front();
    Q.pop();
    for (Edge *P = E[u]; P; P = P->next)
      if (P->cap && H[P->to] > H[u] + 1) {
        H[P->to] = H[u] + 1;
        Q.push(P->to);
      }
  }
  return H[t] != 0x7f7f7f7f;
}
int extend(int u, int left) {
  int r = 0;
  if (u == t) return left;
  for (Edge *P = E[u]; P && r < left; P = P->next)
    if (P->cap && H[P->to] == H[u] + 1) {
      int t;
      t = extend(P->to, min(P->cap, left - r));
      r += t;
      P->cap -= t;
      P->oppo->cap += t;
    }
  if (!r) H[u] = MAX;
  return r;
}
void Work() {
  int ans = 0;
  while (Makelevel()) ans += extend(s, MAX);
  printf("%d\n", ans);
  int num = 0;
  for (int i = (1); i <= (m); i++) {
    for (Edge *P = E[i]; P; P = P->next)
      if (P->to == t && P->cap == 0) Is[i] = 1, num++;
  }
  assert(num == ans);
  for (int i = (1); i <= (n); i++)
    if (ID[i] == 2) {
      int x;
      for (Edge *P = E[N + i]; P; P = P->next)
        if (P->to == s) x = P->cap;
      if (x == 0) continue;
      int now = 2;
      for (Edge *P = E[N + i]; P; P = P->next)
        if (P->to <= m && P->to >= 1 && P->cap == 0) {
          now--;
          printf("%d %d\n", i, P->to);
          Is[P->to] = 0;
        }
      int a = XX[i], b = YY[i], c = ZZ[i];
      if (now && Is[a]) {
        Is[a] = 0;
        now--;
        printf("%d %d\n", i, a);
      }
      if (now && Is[b]) {
        Is[b] = 0;
        now--;
        printf("%d %d\n", i, b);
      }
      if (now && Is[c]) {
        Is[c] = 0;
        now--;
        printf("%d %d\n", i, c);
      }
    }
  for (int i = (1); i <= (n); i++)
    if (ID[i] == 0) {
      for (Edge *P = E[N + i]; P; P = P->next)
        if (P->to >= 1 && P->to <= m && P->cap == 0 && Is[P->to]) {
          Is[P->to] = 0;
          printf("%d %d\n", i, P->to);
        }
    }
  for (int i = (1); i <= (m); i++)
    if (Is[i]) {
      int id = 0;
      for (int j = (1); j <= (n); j++)
        if (ID[j] == 1 && XX[j] <= i && YY[j] >= i &&
            (id == 0 || YY[j] < YY[id]))
          id = j;
      ID[id] = 4;
      printf("%d %d\n", id, i);
      assert(id != 0);
    }
}
void build(int i, int l, int r) {
  T[i].l = l;
  T[i].r = r;
  T[i].id = ++N;
  if (l == r) {
    addedge(N, l, MAX);
    return;
  }
  int M = l + r >> 1;
  build(i << 1, l, M);
  build(i << 1 | 1, M + 1, r);
  addedge(T[i].id, T[i << 1].id, MAX);
  addedge(T[i].id, T[i << 1 | 1].id, MAX);
}
void query(int i, int l, int r, int id) {
  if (l <= T[i].l && T[i].r <= r) {
    addedge(id, T[i].id, 1);
    return;
  }
  int M = T[i].l + T[i].r >> 1;
  if (l <= M) query(i << 1, l, r, id);
  if (r > M) query(i << 1 | 1, l, r, id);
}
void Init() {
  read(n, m);
  N = m;
  build(1, 1, m);
  s = 0;
  t = m * 5 + n + 1;
  for (int i = (1); i <= (m); i++) addedge(i, t, 1);
  for (int i = (1); i <= (n); i++) {
    int id;
    read(id);
    ID[i] = id;
    if (id == 0) {
      addedge(s, N + i, 1);
      int k;
      read(k);
      while (k--) {
        int x;
        read(x);
        addedge(N + i, x, 1);
      }
    } else if (id == 1) {
      addedge(s, N + i, 1);
      int l, r;
      read(l, r);
      query(1, l, r, N + i);
      XX[i] = l;
      YY[i] = r;
    } else {
      addedge(s, N + i, 2);
      int a, b, c;
      read(a, b, c);
      addedge(N + i, a, 1);
      addedge(N + i, b, 1);
      addedge(N + i, c, 1);
      XX[i] = a;
      YY[i] = b;
      ZZ[i] = c;
    }
  }
}
int main() {
  Init();
  int t = 0;
  Work();
  return 0;
}