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>
#pragma GCC optimize(3)
using namespace std;
struct edge {
  int to, cap, rev;
};
int V, maxi;
vector<edge> G[30005];
int level[30005];
int iter[30005];
int lb[30005], rb[30005];
int type[30005], x[30005], y[30005], z[30005];
int n, m;
vector<int> v[30005];
int where[30005];
int id[30005], rev[50000];
void add_edge(int from, int to, int cap) {
  G[from].push_back((edge){to, cap, (int)G[to].size()});
  G[to].push_back((edge){from, 0, (int)G[from].size() - 1});
}
void bfs(int s) {
  memset(level, -1, sizeof(level));
  queue<int> que;
  level[s] = 0;
  que.push(s);
  while (!que.empty()) {
    int v = que.front();
    que.pop();
    for (int i = 0; i < (int)G[v].size(); i++) {
      edge &e = G[v][i];
      if (e.cap > 0 && level[e.to] < 0) {
        level[e.to] = level[v] + 1;
        que.push(e.to);
      }
    }
  }
}
int dfs(int v, int t, int f) {
  if (v == t) return f;
  for (int &i = iter[v]; i < (int)G[v].size(); i++) {
    edge &e = G[v][i];
    if (level[v] < level[e.to] && e.cap > 0) {
      int d = dfs(e.to, t, min(f, e.cap));
      if (d > 0) {
        e.cap -= d;
        G[e.to][e.rev].cap += d;
        return d;
      }
    }
  }
  return 0;
}
int max_flow(int s, int t) {
  int flow = 0;
  for (;;) {
    bfs(s);
    if (level[t] < 0) return flow;
    memset(iter, 0, sizeof(iter));
    int f;
    while ((f = dfs(s, t, 1000000)) > 0) flow += f;
  }
}
void build(int k, int l, int r) {
  lb[k] = l;
  rb[k] = r;
  if (l == r) {
    id[l] = n + k;
    maxi = max(maxi, id[l]);
    rev[n + k] = l;
    return;
  }
  int mid = (l + r) / 2;
  build(k * 2, l, mid);
  build(k * 2 + 1, mid + 1, r);
  add_edge(n + k, n + k * 2, 1000000);
  add_edge(n + k, n + k * 2 + 1, 1000000);
}
void add_range_edge(int v, int k, int l, int r, int x, int y) {
  if (l > y || x > r) return;
  if (l >= x && r <= y) {
    add_edge(v, n + k, 1);
    return;
  }
  int mid = (l + r) / 2;
  add_range_edge(v, k * 2, l, mid, x, y);
  add_range_edge(v, k * 2 + 1, mid + 1, r, x, y);
}
int get_ans(int k, int l, int r) {
  if (l == r) return l;
  int mid = (l + r) / 2;
  for (auto &e : G[n + k]) {
    if (e.to != n + k * 2 && e.to != n + k * 2 + 1) continue;
    if (e.cap == 1000000) continue;
    e.cap++;
    if (e.to == n + k * 2)
      return get_ans(k * 2, l, mid);
    else
      return get_ans(k * 2 + 1, mid + 1, r);
  }
}
int main() {
  scanf("%d%d", &n, &m);
  maxi = 0;
  build(1, 1, m);
  V = maxi;
  int s = V + 1, t = V + 2;
  for (int i = 1; i <= m; i++) add_edge(id[i], t, 1);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &type[i]);
    if (type[i] == 0) {
      add_edge(s, i, 1);
      int k;
      scanf("%d", &k);
      for (int j = 0; j < k; j++) {
        int x;
        scanf("%d", &x);
        add_edge(i, id[x], 1);
      }
    } else if (type[i] == 1) {
      add_edge(s, i, 1);
      int l, r;
      scanf("%d%d", &l, &r);
      add_range_edge(i, 1, 1, m, l, r);
    } else {
      add_edge(s, i, 2);
      scanf("%d%d%d", &x[i], &y[i], &z[i]);
      add_edge(i, id[x[i]], 1);
      add_edge(i, id[y[i]], 1);
      add_edge(i, id[z[i]], 1);
    }
  }
  printf("%d\n", max_flow(s, t));
  for (int i = 1; i <= n; i++) {
    if (type[i] == 1) continue;
    for (auto e : G[i]) {
      if (e.to < n + 1 || e.to > V) continue;
      if (e.cap != 0) continue;
      v[i].push_back(rev[e.to]);
      where[rev[e.to]] = i;
    }
  }
  for (int i = 1; i <= n; i++) {
    if (type[i] != 1) continue;
    for (auto e : G[i]) {
      if (e.to < n + 1 || e.to > V) continue;
      if (e.cap != 0) continue;
      int val = get_ans(e.to - n, lb[e.to - n], rb[e.to - n]);
      v[i].push_back(val);
      where[val] = i;
    }
  }
  for (int i = 1; i <= n; i++) {
    if (type[i] == 2 && (int)v[i].size() == 1) {
      if (v[i][0] != x[i] && where[x[i]]) {
        int u = where[x[i]];
        v[u].clear();
        where[x[i]] = i;
        v[i].push_back(x[i]);
      } else if (v[i][0] != y[i] && where[y[i]]) {
        int u = where[y[i]];
        v[u].clear();
        where[y[i]] = i;
        v[i].push_back(y[i]);
      } else {
        int u = where[z[i]];
        v[u].clear();
        where[z[i]] = i;
        v[i].push_back(z[i]);
      }
    }
  }
  for (int i = 1; i <= m; i++)
    if (where[i]) printf("%d %d\n", where[i], i);
  return 0;
}