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;
template <class T>
inline void init(T& x) {
  x = 0;
  char ch = getchar();
  bool t = 0;
  for (; ch > '9' || ch < '0'; ch = getchar())
    if (ch == '-') t = 1;
  for (; ch >= '0' && ch <= '9'; ch = getchar())
    x = (x << 1) + (x << 3) + (ch - 48);
  if (t) x = -x;
  return;
}
const int MAXN = 2e6;
const int MAXM = 5e6;
const int INF = 1e9;
const int N = 5020;
int S, T;
struct edge {
  int to, next, cap;
} a[MAXM];
int enemy[N];
int head[MAXN], cnt = 0;
inline void add(int x, int y, int z) {
  a[cnt] = (edge){y, head[x], z};
  head[x] = cnt++;
}
inline void add_edge(int x, int y, int z) { add(x, y, z), add(y, x, 0); }
const int MAXNN = 2e4;
int node = 0, TAIL;
int ls[MAXNN], rs[MAXNN];
int n, m;
void Build(int& u, int l, int r) {
  u = ++node;
  if (l == r) return add_edge(T + u, l + n, 1);
  int mid = (l + r) >> 1;
  Build(ls[u], l, mid);
  add_edge(T + u, T + ls[u], INF);
  Build(rs[u], mid + 1, r);
  add_edge(T + u, T + rs[u], INF);
  return;
}
int A[N][3], du[N], cur[MAXN], d[MAXN], ToT[N], tp[N];
void Link(int u, int l, int r, int L, int R, int fr) {
  if (l >= L && r <= R) return add_edge(fr, T + u, 1);
  int mid = (l + r) >> 1;
  if (mid >= L) Link(ls[u], l, mid, L, R, fr);
  if (mid < R) Link(rs[u], mid + 1, r, L, R, fr);
  return;
}
queue<int> Q;
inline bool bfs() {
  while (!Q.empty()) Q.pop();
  for (int i = S; i <= TAIL; ++i) d[i] = 0;
  d[S] = 1, Q.push(S);
  while (!Q.empty()) {
    int u = Q.front();
    Q.pop();
    for (int v, i = head[u]; ~i; i = a[i].next) {
      v = a[i].to;
      if (!a[i].cap || d[v]) continue;
      d[v] = d[u] + 1;
      if (v == T) return 1;
      Q.push(v);
    }
  }
  return d[T];
}
int dfs(int u, int flow) {
  if (u == T) return flow;
  int res = flow;
  for (int v, &i = cur[u]; ~i; i = a[i].next) {
    v = a[i].to;
    if (!a[i].cap || d[v] != d[u] + 1) continue;
    int f = dfs(v, min(res, a[i].cap));
    if (!f) d[v] = 0;
    res -= f, a[i].cap -= f, a[i ^ 1].cap += f;
    if (!res) break;
  }
  return flow - res;
}
inline int Dinic() {
  int flow = 0;
  while (bfs()) {
    for (int i = 0; i <= TAIL; ++i) cur[i] = head[i];
    int f;
    flow += (f = dfs(S, INF));
  }
  return flow;
}
void DFS(int u, int fr) {
  if (u <= n && u >= 1) {
    enemy[fr] = u, ++du[u];
    return;
  }
  for (int v, i = head[u]; ~i; i = a[i].next) {
    v = a[i].to;
    if ((i & 1) && a[i].cap) {
      --a[i].cap, ++a[i ^ 1].cap;
      DFS(v, fr);
      return;
    }
  }
}
int main() {
  init(n), init(m);
  int rt = 0;
  memset(head, -1, sizeof(head));
  S = 0, T = n + m + 1;
  Build(rt, 1, m);
  for (int i = 1; i <= m; ++i) ToT[i] = cnt, add_edge(i + n, T, 1);
  for (int i = 1; i <= n; ++i) {
    init(tp[i]);
    if (!tp[i]) {
      add_edge(S, i, 1);
      int k;
      init(k);
      for (int j = 1; j <= k; ++j) {
        int v;
        init(v);
        add_edge(i, v + n, 1);
      }
    } else if (tp[i] == 1) {
      add_edge(S, i, 1);
      int l, r;
      init(l), init(r);
      A[i][1] = l, A[i][2] = r;
      Link(1, 1, m, l, r, i);
    } else if (tp[i] == 2) {
      add_edge(S, i, 2);
      init(A[i][0]), add_edge(i, A[i][0] + n, 1);
      init(A[i][1]), add_edge(i, A[i][1] + n, 1);
      init(A[i][2]), add_edge(i, A[i][2] + n, 1);
    }
  }
  TAIL = T + node;
  int ans = Dinic();
  cout << ans << endl;
  for (int u = n + 1; u <= n + m; ++u) {
    if (!a[ToT[u - n]].cap) DFS(u, u - n);
  }
  for (int i = 1; i <= n; ++i) {
    if (tp[i] == 2) {
      if (du[i] == 1) {
        for (int j = 0; j < 3; ++j) {
          int v = A[i][j];
          if (enemy[v] != i) {
            enemy[v] = i;
            break;
          }
        }
      }
    }
  }
  for (int i = 1; i <= m; ++i)
    if (enemy[i]) printf("%d %d\n", enemy[i], i);
  return 0;
}