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 = 5010;
const int maxm = int(1e5) + 100;
const int inf = 0x3fffffff;
struct LINK {
  int id, next, flow;
};
int n, m, now, SS, TT, total, ans;
int h[maxn * 5], q[maxn * 5], level[maxn * 5], nx[maxn * 5];
int idx[maxn * 5], Tlink[maxn * 5];
LINK t[(maxn * 15 + maxm + maxn * 5) * 2];
pair<int, int> dat;
vector<pair<int, int> > plan;
void join(int u, int v, int fl) {
  t[now].id = v;
  t[now].next = h[u];
  t[now].flow = fl;
  h[u] = now++;
  t[now].id = u;
  t[now].next = h[v];
  t[now].flow = 0;
  h[v] = now++;
}
void build(int cur, int L, int R) {
  h[TT + cur] = -1;
  total = max(total, TT + cur);
  if (L == R) {
    idx[TT + cur] = L;
    join(TT + cur, TT, 1);
    Tlink[L] = now;
    return;
  }
  int mid = (L + R) >> 1;
  build(cur << 1, L, mid);
  build(cur << 1 | 1, mid + 1, R);
  join(TT + cur, TT + (cur << 1), inf);
  join(TT + cur, TT + (cur << 1 | 1), inf);
}
void findidx(int cur, int L, int R, int &num) {
  if (dat.first > R || dat.second < L) return;
  if (dat.first <= L && R <= dat.second) {
    join(num, TT + cur, 1);
    return;
  }
  int mid = (L + R) >> 1;
  findidx(cur << 1, L, mid, num);
  findidx(cur << 1 | 1, mid + 1, R, num);
}
void read() {
  scanf("%d%d", &m, &n);
  SS = 0;
  TT = m + 1;
  for (int i = 0; i <= TT; ++i) h[i] = -1;
  now = 0;
  build(1, 1, n);
  for (int i = 1; i <= m; ++i) {
    int type;
    scanf("%d", &type);
    if (type == 0) {
      int s, x;
      scanf("%d", &s);
      join(SS, i, 1);
      for (int j = 1; j <= s; ++j) {
        scanf("%d", &x);
        dat.first = dat.second = x;
        findidx(1, 1, n, i);
      }
    } else if (type == 1) {
      int L, R;
      scanf("%d%d", &L, &R);
      join(SS, i, 1);
      dat.first = L;
      dat.second = R;
      findidx(1, 1, n, i);
    } else {
      join(SS, i, 0);
      ans += 2;
      int x;
      for (int j = 0; j < 3; ++j) {
        scanf("%d", &x);
        dat.first = dat.second = x;
        findidx(1, 1, n, i);
        swap(t[now - 1].flow, t[now - 2].flow);
        swap(t[Tlink[x] - 1].flow, t[Tlink[x] - 2].flow);
      }
      swap(t[now - 1].flow, t[now - 2].flow);
      swap(t[Tlink[x] - 1].flow, t[Tlink[x] - 2].flow);
    }
  }
}
bool build_level() {
  int head = 1, tail = 1;
  q[1] = SS;
  for (int i = 0; i <= total; ++i) level[i] = -1;
  level[SS] = 0;
  while (head <= tail) {
    int cur = q[head++];
    for (int i = h[cur]; i > -1; i = t[i].next)
      if (level[t[i].id] == -1 && t[i].flow) {
        level[t[i].id] = level[cur] + 1;
        q[++tail] = t[i].id;
        if (t[i].id == TT) return true;
      }
  }
  return false;
}
int dinic(int cur, int rest) {
  if (cur == TT) return rest;
  int delta = 0;
  for (int i = nx[cur]; i > -1; i = nx[cur] = t[i].next)
    if (level[cur] + 1 == level[t[i].id] && t[i].flow) {
      int tmp = dinic(t[i].id, min(t[i].flow, rest));
      delta += tmp;
      rest -= tmp;
      t[i].flow -= tmp;
      t[i ^ 1].flow += tmp;
      if (rest == 0) break;
    }
  return delta;
}
int findroute(int cur) {
  while (idx[cur] == 0) {
    for (int j = h[cur]; j > -1; j = t[j].next)
      if (t[j].id > cur && t[j ^ 1].flow) {
        t[j ^ 1].flow--;
        cur = t[j].id;
        break;
      }
  }
  return cur;
}
void solve() {
  while (build_level()) {
    for (int i = 0; i <= total; ++i) nx[i] = h[i];
    ans += dinic(SS, inf);
  }
  printf("%d\n", ans);
  for (int i = 1; i <= m; ++i) {
    int num = 0;
    for (int j = h[i]; j > -1; j = t[j].next)
      if (t[j].id == SS) {
        num = j ^ 1;
        break;
      }
    if (t[num].flow) continue;
    plan.push_back(make_pair(idx[findroute(i)], i));
    if (t[num ^ 1].flow == 0) plan.push_back(make_pair(idx[findroute(i)], i));
  }
  sort(plan.begin(), plan.end());
  for (auto &value : plan) printf("%d %d\n", value.second, value.first);
}
int main() {
  read();
  solve();
  return 0;
}