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;
int read() {
  char ch = getchar();
  int x = 0, fl = 1;
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') fl = -1;
  for (; isdigit(ch); ch = getchar()) x = (x << 3) + (x << 1) + (ch - '0');
  return x * fl;
}
const int N = 30005;
const int M = 10000005;
const int INF = 1e9;
int n, m, _, lev[N], s, t;
int ver[M], cap[M], nxt[M], fst[N], cur[N], tot;
void addedge(int x, int y, int c) {
  ver[++tot] = y;
  cap[tot] = c;
  nxt[tot] = fst[x];
  fst[x] = tot;
  ver[++tot] = x;
  cap[tot] = 0;
  nxt[tot] = fst[y];
  fst[y] = tot;
}
bool bfs() {
  memset(lev, -1, sizeof(lev));
  queue<int> q;
  while (!q.empty()) q.pop();
  q.push(s);
  lev[s] = 0;
  while (!q.empty()) {
    int x = q.front();
    q.pop();
    for (int i = fst[x]; ~i; i = nxt[i]) {
      int y = ver[i], c = cap[i];
      if (c && lev[y] < 0) lev[y] = lev[x] + 1, q.push(y);
    }
  }
  return lev[t] >= 0;
}
int dfs(int x, int lim) {
  if (x == t) return lim;
  int res = 0;
  for (int i = cur[x]; ~i; i = nxt[i]) {
    int y = ver[i], c = cap[i];
    if (c && lev[y] == lev[x] + 1) {
      int tmp = dfs(y, min(lim, c));
      if (!tmp) continue;
      lim -= tmp;
      res += tmp;
      cap[i] -= tmp;
      cap[i ^ 1] += tmp;
      if (!lim) {
        cur[x] = i;
        return res;
      }
    }
  }
  cur[x] = -1;
  return res;
}
int MF() {
  int ans = 0;
  while (bfs()) {
    memcpy(cur, fst, sizeof(cur));
    ans += dfs(s, INF);
  }
  return ans;
}
namespace seg {
int p[N << 2];
void build(int rt, int l, int r) {
  if (l == r) {
    p[rt] = l;
    return;
  }
  int mid = (l + r) >> 1;
  p[rt] = ++_;
  build(rt << 1, l, mid);
  build(rt << 1 | 1, mid + 1, r);
  addedge(p[rt], p[rt << 1], INF);
  addedge(p[rt], p[rt << 1 | 1], INF);
}
void link(int rt, int l, int r, int ql, int qr, int pv) {
  if (ql <= l && r <= qr) {
    addedge(pv, p[rt], 1);
    return;
  }
  int mid = (l + r) >> 1;
  if (ql <= mid) link(rt << 1, l, mid, ql, qr, pv);
  if (qr > mid) link(rt << 1 | 1, mid + 1, r, ql, qr, pv);
}
}  // namespace seg
struct node {
  int fl, a, b, c;
  node(int _fl = 0, int _a = 0, int _b = 0, int _c = 0) {
    fl = _fl;
    a = _a;
    b = _b;
    c = _c;
  }
} rr[N];
int anc, ans[N], ct[N];
void find(int x, int ff) {
  if (anc) return;
  if (x > n && x <= m + n) {
    anc = x - n;
    return;
  }
  for (int i = fst[x]; ~i; i = nxt[i]) {
    int y = ver[i], c = cap[i];
    if (y != ff && c) {
      cap[i]--;
      find(y, x);
      return;
    }
  }
}
int main() {
  m = read();
  n = read();
  _ = n + m;
  s = 0;
  t = ++_;
  tot = 1;
  memset(fst, -1, sizeof(fst));
  seg::build(1, 1, n);
  for (int i = 1; i <= m; i++) {
    int opt = read(), tmp = i + n;
    if (!opt) {
      addedge(s, tmp, 1);
      int k = read();
      while (k--) {
        int x = read();
        addedge(tmp, x, 1);
      }
    } else if (opt == 1) {
      addedge(s, tmp, 1);
      int l = read(), r = read();
      seg::link(1, 1, n, l, r, tmp);
    } else {
      addedge(s, tmp, 2);
      int a = read(), b = read(), c = read();
      addedge(tmp, a, 1);
      addedge(tmp, b, 1);
      addedge(tmp, c, 1);
      rr[i] = node(1, a, b, c);
    }
  }
  for (int i = 1; i <= n; i++) addedge(i, t, 1);
  cout << MF() << '\n';
  for (int i = fst[t]; ~i; i = nxt[i]) {
    if (cap[i]) {
      anc = 0;
      find(ver[i], t);
      ans[ver[i]] = anc;
      ct[anc]++;
    }
  }
  for (int i = 1; i <= m; i++) {
    if (rr[i].fl) {
      if (ct[i] == 1) {
        if (ans[rr[i].a] != i)
          ans[rr[i].a] = i;
        else
          ans[rr[i].b] = i;
      }
    }
  }
  for (int i = 1; i <= n; i++)
    if (ans[i]) cout << ans[i] << ' ' << i << '\n';
  return 0;
}