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 N = 1e6 + 10;
int n, m, cnt;
int head[N], rest[N], to[N], flow[N], tot = 1, S, T;
int dis[N];
bool fwd[N];
void add_sig(int u, int v, int w) {
  to[++tot] = v, flow[tot] = w, rest[tot] = head[u], head[u] = tot;
}
void add(int u, int v, int w) {
  add_sig(u, v, w);
  fwd[tot] = 1;
  add_sig(v, u, 0);
}
int bfs() {
  for (int i = 1; i <= cnt; ++i) dis[i] = -1;
  queue<int> q;
  q.push(S), dis[S] = 1;
  while (q.size()) {
    int u = q.front();
    q.pop();
    for (int i = head[u]; i; i = rest[i]) {
      int v = to[i];
      if (flow[i] && dis[v] == -1) {
        dis[v] = dis[u] + 1;
        q.push(v);
      }
    }
  }
  return dis[T] != -1;
}
int dfs(int u, int f) {
  if (u == T || !f) return f;
  int use = 0;
  for (int i = head[u]; i; i = rest[i]) {
    int v = to[i];
    if (dis[v] == dis[u] + 1 && flow[i]) {
      int a = dfs(v, min(flow[i], f - use));
      use += a, flow[i] -= a, flow[i ^ 1] += a;
      if (use == f) break;
    }
  }
  if (!use) dis[u] = -1;
  return use;
}
int mxflow() {
  int res = 0;
  while (bfs()) res += dfs(S, 0x3f3f3f3f);
  return res;
}
int vis[N], tmp[N], bel[N];
void build(int id, int l, int r) {
  cnt = max(cnt, id);
  int mid = (l + r) >> 1;
  if (l == r) {
    tmp[l] = id;
    bel[id] = l;
  } else {
    build((id << 1), l, mid), build((id << 1 | 1), mid + 1, r);
    add(id, (id << 1), 0x3f3f3f3f), add(id, (id << 1 | 1), 0x3f3f3f3f);
  }
}
void ask(int id, int l, int r, int ql, int qr, int src) {
  int mid = (l + r) >> 1;
  if (ql <= l && r <= qr) {
    add(src, id, 1);
  } else if (qr <= mid) {
    ask((id << 1), l, mid, ql, qr, src);
  } else if (ql >= mid + 1) {
    ask((id << 1 | 1), mid + 1, r, ql, qr, src);
  } else {
    ask((id << 1), l, mid, ql, mid, src);
    ask((id << 1 | 1), mid + 1, r, mid + 1, qr, src);
  }
}
int pos[N], rem[N];
vector<pair<int, int> > output;
struct T {
  int ty, a, b, c;
} inp[N];
int go(int u, int fr = 0) {
  if (bel[u]) {
    int res = bel[u];
    bel[u] = 0;
    return res;
  }
  for (int &i = head[u]; i; i = rest[i]) {
    int v = to[i];
    if (flow[i] != 1 && flow[i] != 0x3f3f3f3f && fwd[i]) {
      flow[i]++;
      return go(v, u);
    }
  }
  return -1;
}
int poi[N];
int main() {
  int ans = 0;
  scanf("%d%d", &n, &m);
  build(1, 1, m);
  S = ++cnt, T = ++cnt;
  for (int i = 1; i <= n; ++i) {
    pos[i] = ++cnt;
    int ty;
    scanf("%d", &ty);
    inp[i].ty = ty;
    if (ty == 0) {
      int k;
      scanf("%d", &k);
      for (int j = 1; j <= k; ++j) {
        int tar;
        scanf("%d", &tar);
        add(pos[i], tmp[tar], 1);
      }
      add(S, pos[i], 1);
    } else if (ty == 1) {
      int l, r;
      scanf("%d%d", &l, &r);
      ask(1, 1, m, l, r, pos[i]);
      add(S, pos[i], 1);
    } else {
      int a, b, c;
      scanf("%d%d%d", &a, &b, &c);
      vis[a] = vis[b] = vis[c] = 1;
      add(tmp[a], pos[i], 1);
      add(tmp[b], pos[i], 1);
      add(tmp[c], pos[i], 1);
      add(pos[i], T, 1);
      ans += 2;
      inp[i].a = a, inp[i].b = b, inp[i].c = c;
    }
  }
  for (int i = 1; i <= m; ++i) {
    if (!vis[i]) {
      add(tmp[i], T, 1);
    }
  }
  printf("%d\n", ans + mxflow());
  for (int i = head[S]; i; i = rest[i]) {
    int v = to[i];
    if (flow[i] == 0) {
      poi[v] = 1;
    }
  }
  for (int i = 1; i <= n; ++i) {
    if (inp[i].ty != 2) {
      if (poi[pos[i]]) {
        int tar = go(pos[i]);
        if (tar != -1) {
          output.push_back(make_pair(i, tar));
          rem[tar] = 1;
        }
      }
    }
  }
  for (int i = 1; i <= n; ++i) {
    if (inp[i].ty == 2) {
      int p = 0;
      if (!rem[inp[i].a] && p < 2) {
        ++p;
        output.push_back(make_pair(i, inp[i].a));
      }
      if (!rem[inp[i].b] && p < 2) {
        ++p;
        output.push_back(make_pair(i, inp[i].b));
      }
      if (!rem[inp[i].c] && p < 2) {
        ++p;
        output.push_back(make_pair(i, inp[i].c));
      }
    }
  }
  for (int i = 0; i < output.size(); ++i) {
    printf("%d %d\n", output[i].first, output[i].second);
  }
}