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 = 4e4 + 5, maxm = 2e5 + 5;
struct Edge {
  int v, next, u, cap;
} edge[maxm];
int k, head[maxn], dist[maxn], que[maxn], current[maxn];
int st, ed, POINT;
inline void dinic_init(int tot_point) {
  memset(head, -1, sizeof(head[0]) * (tot_point + 3));
  k = -1;
}
void add_edge(int u, int v, int cap) {
  edge[++k].u = u;
  edge[k].v = v;
  edge[k].cap = cap;
  edge[k].next = head[u];
  head[u] = k;
  edge[++k].u = v;
  edge[k].v = u;
  edge[k].cap = 0;
  edge[k].next = head[v];
  head[v] = k;
}
bool bfs() {
  int fro, top;
  memset(dist, 0, sizeof(dist[0]) * (POINT + 4));
  dist[st] = 1;
  fro = top = 1;
  que[fro] = st;
  while (fro <= top) {
    int p = que[fro++];
    for (int kk = head[p]; ~kk; kk = edge[kk].next) {
      int v = edge[kk].v, cap = edge[kk].cap;
      if (cap && !dist[v]) {
        dist[v] = dist[p] + 1;
        que[++top] = v;
        if (v == ed) return 1;
      }
    }
  }
  return 0;
}
int dfs(int u, int maxflow) {
  if (u == ed || maxflow == 0) return maxflow;
  int t = 0;
  for (int& kk = current[u]; ~kk; kk = edge[kk].next) {
    int v = edge[kk].v, cap = edge[kk].cap;
    if (cap && dist[v] == dist[u] + 1) {
      int f = dfs(v, min(cap, maxflow - t));
      t += f;
      edge[kk].cap -= f;
      edge[kk ^ 1].cap += f;
      if (t == maxflow) return t;
    }
  }
  if (t == 0) dist[u] = -1;
  return t;
}
int dinic() {
  int maxnflow = 0, t;
  while (bfs()) {
    for (int i = 0; i <= ed; ++i) current[i] = head[i];
    while (t = dfs(st, 100000000)) maxnflow += t;
  }
  return maxnflow;
}
int id[maxn], rev[maxn], tot;
void build(int x, int l, int r) {
  if (l == r) {
    id[l] = x;
    rev[x] = l;
  } else {
    int mid = l + r >> 1, z = x + (mid - l + 1 << 1);
    build(x + 1, l, mid);
    build(z, mid + 1, r);
    add_edge(x, x + 1, 100000000);
    add_edge(x, z, 100000000);
  }
}
void update(int nd, int l, int r, int L, int R) {
  if (L <= l && r <= R) {
    add_edge(tot, nd, 1);
    return;
  }
  int mid = l + r >> 1, z = nd + (mid - l + 1 << 1);
  if (L <= mid) update(nd + 1, l, mid, L, R);
  if (R > mid) update(z, mid + 1, r, L, R);
}
const int N = 5e3 + 5;
bool use[N];
int type[N];
vector<int> operation[N];
inline void solve_weapon_type_2(int& remain, int ship, int weapon) {
  --remain;
  use[ship] = false;
  printf("%d %d\n", weapon, ship);
}
void solve_weapon_on_spaceship(int n, int m) {
  for (int i = 1; i <= m; ++i)
    for (int j = head[id[i]]; ~j; j = edge[j].next)
      if (edge[j].v == ed && !edge[j].cap) use[i] = true;
  int tree_point = (m << 1) - 1;
  for (int i = 1; i <= n; ++i)
    if (type[i] == 2) {
      bool found = false;
      for (int j = head[i + tree_point]; ~j; j = edge[j].next) {
        if (edge[j].v == st && edge[j].cap) {
          found = true;
          break;
        }
      }
      if (found) {
        int remain = 2;
        for (int j = head[i + tree_point]; ~j; j = edge[j].next)
          if (!edge[j].cap) solve_weapon_type_2(remain, rev[edge[j].v], i);
        for (int j = 0; remain; ++j)
          if (use[operation[i][j]])
            solve_weapon_type_2(remain, operation[i][j], i);
      }
    }
  for (int i = 1; i <= n; ++i)
    if (!type[i]) {
      for (int j = head[i + tree_point]; ~j; j = edge[j].next)
        if (!edge[j].cap && use[rev[edge[j].v]]) {
          use[rev[edge[j].v]] = false;
          printf("%d %d\n", i, rev[edge[j].v]);
          break;
        }
    }
  for (int i = 1; i <= m; ++i)
    if (use[i]) {
      int p = -1;
      for (int j = 1; j <= n; ++j)
        if (type[j] == 1 && operation[j][0] <= i && operation[j][1] >= i &&
            (!~p || operation[j][1] < operation[p][1])) {
          p = j;
        }
      type[p] = -1;
      printf("%d %d\n", p, i);
    }
}
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  dinic_init((m << 1) - 1 + n + 2);
  build(1, 1, m);
  tot = id[m];
  st = 0;
  int op, num, x, l, r;
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &type[i]);
    ++tot;
    operation[i].clear();
    if (!type[i]) {
      scanf("%d", &num);
      while (num--) {
        scanf("%d", &x);
        add_edge(tot, id[x], 1);
      }
      add_edge(st, tot, 1);
    } else if (type[i] == 1) {
      scanf("%d %d", &l, &r);
      operation[i].emplace_back(l);
      operation[i].emplace_back(r);
      update(1, 1, m, l, r);
      add_edge(st, tot, 1);
    } else {
      scanf("%d %d %d", &x, &l, &r);
      add_edge(st, tot, 2);
      operation[i].emplace_back(x);
      operation[i].emplace_back(l);
      operation[i].emplace_back(r);
      add_edge(tot, id[x], 1);
      add_edge(tot, id[l], 1);
      add_edge(tot, id[r], 1);
    }
  }
  ed = ++tot;
  POINT = ed + 1;
  for (int i = 1; i <= m; i++) add_edge(id[i], ed, 1);
  printf("%d\n", dinic());
  solve_weapon_on_spaceship(n, m);
  return 0;
}