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 = 2e5 + 5;
const int MAXM = 2e6 + 5;
int N, M, V, st, se;
struct node {
  int x, y, z;
  int id;
} p[5005];
int hash_weapon[MAXN], cnt_p;
struct edge {
  int to, next, cf;
} e[MAXM];
int head[MAXN], cnt_adj;
void add_edge(int, int, int);
int Dinic(int, int);
int buck[MAXN];
struct ST {
  int left, right;
  int id;
  int move;
} sst[MAXN];
int nid[MAXN], hash_id[MAXN], newid, hash_sst[MAXN];
void build(int pos, int l, int r);
void update(int pos, int l, int r, int x);
int mark[MAXN];
struct node1 {
  int pos, u;
  int id;
};
vector<node1> A;
bool cmp1(node1 a, node1 b) {
  return sst[a.pos].right - sst[a.pos].left <
         sst[b.pos].right - sst[b.pos].left;
}
int main() {
  scanf("%d%d", &N, &M);
  st = N + 5 * M + 1, se = st + 1;
  cnt_adj = 1;
  V = se;
  newid = N;
  build(1, 1, M);
  for (int i = 1; i <= N; i++) {
    int op;
    scanf("%d", &op);
    mark[i] = op;
    if (op == 0) {
      add_edge(st, i, 1);
      add_edge(i, st, 0);
      int K;
      scanf("%d", &K);
      while (K--) {
        int x;
        scanf("%d", &x);
        add_edge(i, nid[x], 1);
        add_edge(nid[x], i, 0);
      }
    } else if (op == 1) {
      add_edge(st, i, 1);
      add_edge(i, st, 0);
      int x, y;
      scanf("%d%d", &x, &y);
      update(1, x, y, i);
    } else {
      add_edge(st, i, 2);
      add_edge(i, st, 0);
      cnt_p++;
      scanf("%d%d%d", &p[cnt_p].x, &p[cnt_p].y, &p[cnt_p].z);
      p[cnt_p].id = i;
      add_edge(i, nid[p[cnt_p].x], 1);
      add_edge(nid[p[cnt_p].x], i, 0);
      add_edge(i, nid[p[cnt_p].y], 1);
      add_edge(nid[p[cnt_p].y], i, 0);
      add_edge(i, nid[p[cnt_p].z], 1);
      add_edge(nid[p[cnt_p].z], i, 0);
    }
  }
  int ans = Dinic(st, se);
  for (int u = 1; u <= N; u++)
    if (mark[u] != 1)
      for (int i = head[u]; i; i = e[i].next) {
        if (!e[i].cf) {
          hash_weapon[hash_id[e[i].to]] = u;
          continue;
        }
      }
  for (int u = 1; u <= N; u++)
    if (mark[u] == 1) {
      for (int i = head[u]; i; i = e[i].next) {
        if (!e[i].cf) {
          A.push_back(node1{hash_sst[e[i].to], u});
          break;
        }
      }
    }
  sort(A.begin(), A.end(), cmp1);
  for (auto item : A) {
    while (hash_weapon[sst[item.pos].left + sst[item.pos].move] &&
           sst[item.pos].left + sst[item.pos].move <= sst[item.pos].right)
      sst[item.pos].move++;
    if (sst[item.pos].left + sst[item.pos].move <= sst[item.pos].right)
      hash_weapon[sst[item.pos].left + sst[item.pos].move] = item.u;
    sst[item.pos].move++;
  }
  for (int i = 1; i <= cnt_p; i++) {
    int x, y, z;
    int hx, hy, hz;
    x = p[i].x, y = p[i].y, z = p[i].z;
    hx = hash_weapon[x], hy = hash_weapon[y], hz = hash_weapon[z];
    buck[hx]++, buck[hy]++, buck[hz]++;
    if (buck[p[i].id] == 1) {
      if (hash_weapon[x] != p[i].id) {
        hash_weapon[x] = p[i].id;
      } else if (hash_weapon[y] != p[i].id) {
        hash_weapon[y] = p[i].id;
      } else if (hash_weapon[z] != p[i].id) {
        hash_weapon[z] = p[i].id;
      }
    }
    buck[hx]--, buck[hy]--, buck[hz]--;
  }
  printf("%d\n", ans);
  for (int i = 1; i <= M; i++)
    if (hash_weapon[i]) printf("%d %d\n", hash_weapon[i], i);
  return 0;
}
void build(int pos, int l, int r) {
  sst[pos].left = l, sst[pos].right = r, sst[pos].id = ++newid;
  hash_sst[newid] = pos;
  if (l == r) {
    nid[l] = newid;
    hash_id[newid] = l;
    add_edge(nid[l], se, 1);
    add_edge(se, nid[l], 0);
    return;
  }
  int lc = pos << 1, rc = lc + 1;
  int mid = (l + r) >> 1;
  build(lc, l, mid);
  build(rc, mid + 1, r);
  add_edge(sst[pos].id, sst[lc].id, 1e8);
  add_edge(sst[lc].id, sst[pos].id, 0);
  add_edge(sst[pos].id, sst[rc].id, 1e8);
  add_edge(sst[rc].id, sst[pos].id, 0);
}
void update(int pos, int l, int r, int x) {
  if (l <= sst[pos].left && sst[pos].right <= r) {
    add_edge(x, sst[pos].id, 1);
    add_edge(sst[pos].id, x, 0);
    return;
  }
  int lc = pos << 1, rc = lc + 1;
  int mid = (sst[pos].left + sst[pos].right) >> 1;
  if (l <= mid) update(lc, l, r, x);
  if (mid < r) update(rc, l, r, x);
}
int dep[MAXN], cur[MAXN];
bool Dinic_bfs(int, int);
int Dinic_dfs(int, int, int);
int Dinic(int st, int se) {
  int maxflow = 0;
  while (Dinic_bfs(st, se)) {
    for (int i = 1; i <= V; i++) cur[i] = head[i];
    int val;
    while ((val = Dinic_dfs(st, se, 1e9))) {
      maxflow += val;
    }
  }
  return maxflow;
}
bool Dinic_bfs(int st, int se) {
  queue<int> Q;
  memset(dep, 0, sizeof(dep));
  dep[st] = 1;
  Q.push(st);
  while (!Q.empty()) {
    int u = Q.front();
    Q.pop();
    for (int i = head[u]; i; i = e[i].next) {
      int v = e[i].to, cf = e[i].cf;
      if (cf && !dep[v]) {
        dep[v] = dep[u] + 1;
        Q.push(v);
      }
    }
  }
  return dep[se] != 0;
}
int Dinic_dfs(int u, int se, int cf_min) {
  if (u == se || !cf_min) return cf_min;
  for (int &i = cur[u]; i; i = e[i].next) {
    int v = e[i].to, cf = e[i].cf;
    if (cf && dep[v] == dep[u] + 1) {
      int val = Dinic_dfs(v, se, min(cf_min, cf));
      if (val) {
        e[i].cf -= val;
        e[i ^ 1].cf += val;
        return val;
      }
    }
  }
  return 0;
}
void add_edge(int x, int y, int z) {
  e[++cnt_adj].to = y;
  e[cnt_adj].cf = z;
  e[cnt_adj].next = head[x];
  head[x] = cnt_adj;
}