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;
struct weapon {
  int tp, l, r, a, b, c, k;
};
weapon wp[22011];
struct Maxflow {
  struct edge {
    int from, to;
    long long flow, capacity;
  };
  int s, t;
  vector<edge> edg;
  vector<int> g[22011];
  int dist[22011], visited[22011];
  int cur[22011];
  void init() {
    edg.clear();
    int i;
    for (i = 0; i < 22011; i++) {
      g[i].clear();
    }
  }
  void addedge(int from, int to, long long capacity) {
    edge e1 = edge{from, to, 0ll, capacity};
    edge e2 = edge{to, from, 0ll, 0ll};
    edg.push_back(e1), edg.push_back(e2);
    g[from].push_back((int)edg.size() - 2);
    g[to].push_back((int)edg.size() - 1);
  }
  bool bfs() {
    memset(visited, 0, sizeof(visited));
    memset(dist, 0, sizeof(dist));
    queue<int> q;
    q.push(s);
    visited[s] = 1;
    dist[s] = 0;
    while (!q.empty()) {
      int v = q.front();
      q.pop();
      for (int i = 0; i < (int)g[v].size(); i++) {
        edge &e = edg[g[v][i]];
        int nxt = e.to;
        if (!visited[nxt] && e.capacity > e.flow) {
          dist[nxt] = dist[v] + 1;
          q.push(nxt);
          visited[nxt] = 1;
        }
      }
    }
    return visited[t];
  }
  long long dfs(int x, long long cp) {
    if (x == t || cp == 0) {
      return cp;
    }
    long long flow = 0, newflow;
    for (int &y = cur[x]; y < (int)g[x].size(); y++) {
      edge &e = edg[g[x][y]];
      if (dist[x] + 1 == dist[e.to]) {
        long long minn = min(cp, e.capacity - e.flow);
        newflow = dfs(e.to, minn);
        if (newflow > 0) {
          e.flow += newflow;
          edg[g[x][y] ^ 1].flow -= newflow;
          flow += newflow;
          cp -= newflow;
          if (cp == 0) {
            break;
          }
        }
      }
    }
    return flow;
  }
  long long Dinic() {
    long long flow = 0;
    while (bfs()) {
      memset(cur, 0, sizeof(cur));
      flow += dfs(s, 10000000000ll);
    }
    return flow;
  }
};
Maxflow mf;
int wid[22011 * 10];
int cnt = 0;
int n, m;
int mt[22011];
void build(int l, int r, int index) {
  if (l > r) return;
  if (l == r) {
    wid[index] = l;
    return;
  }
  wid[index] = ++cnt;
  build(l, ((l + r) >> 1), (index << 1));
  build(((l + r) >> 1) + 1, r, (index << 1 | 1));
  mf.addedge(wid[index], wid[(index << 1)], 10000000000ll);
  mf.addedge(wid[index], wid[(index << 1 | 1)], 10000000000ll);
}
void update(int start, int end, int l, int r, int index, int v) {
  if (start > end || l > r || start > r || l > end) return;
  if (start <= l && r <= end) {
    mf.addedge(v, wid[index], 1);
    return;
  }
  if (end <= ((l + r) >> 1)) {
    update(start, end, l, ((l + r) >> 1), (index << 1), v);
  } else if (start >= ((l + r) >> 1) + 1) {
    update(start, end, ((l + r) >> 1) + 1, r, (index << 1 | 1), v);
  } else {
    update(start, end, l, ((l + r) >> 1), (index << 1), v);
    update(start, end, ((l + r) >> 1) + 1, r, (index << 1 | 1), v);
  }
}
void find(int v, int id, int pre) {
  if (mt[id] != 0) return;
  if (v > m && v <= n + m) {
    mt[id] = v - m;
    return;
  }
  int i;
  for (i = 0; i < (int)mf.g[v].size(); ++i) {
    auto e = mf.edg[mf.g[v][i]];
    if (e.flow < 0 && e.to != pre) {
      find(e.to, id, v);
      mf.edg[mf.g[v][i]].flow++;
      return;
    }
  }
}
int tol[22011];
int main() {
  int i, j;
  scanf("%d%d", &n, &m);
  cnt = n + m;
  mf.s = 0, mf.t = 22011 - 1;
  build(1, m, 1);
  for (i = 1; i <= n; ++i) {
    scanf("%d", &wp[i].tp);
    if (wp[i].tp == 0) {
      mf.addedge(mf.s, i + m, 1);
      scanf("%d", &wp[i].k);
      for (j = 0; j < wp[i].k; ++j) {
        int v;
        scanf("%d", &v);
        mf.addedge(i + m, v, 1);
      }
    } else if (wp[i].tp == 1) {
      mf.addedge(mf.s, i + m, 1);
      scanf("%d%d", &wp[i].l, &wp[i].r);
      update(wp[i].l, wp[i].r, 1, m, 1, i + m);
    } else {
      mf.addedge(mf.s, i + m, 2);
      scanf("%d%d%d", &wp[i].a, &wp[i].b, &wp[i].c);
      mf.addedge(i + m, wp[i].a, 1);
      mf.addedge(i + m, wp[i].b, 1);
      mf.addedge(i + m, wp[i].c, 1);
    }
  }
  for (i = 1; i <= m; ++i) {
    mf.addedge(i, mf.t, 1);
  }
  printf("%I64d\n", mf.Dinic());
  for (i = 0; i < (int)mf.g[mf.t].size(); ++i) {
    auto &e = mf.edg[mf.g[mf.t][i]];
    if (e.flow < e.capacity) {
      find(e.to, e.to, mf.t);
    }
  }
  for (i = 1; i <= m; ++i) {
    if (mt[i]) {
      tol[mt[i]]++;
    }
  }
  for (i = 1; i <= n; ++i) {
    if (wp[i].tp == 2 && tol[i] == 1) {
      if (mt[wp[i].a] != i) {
        mt[wp[i].a] = i;
      } else {
        mt[wp[i].b] = i;
      }
    }
  }
  for (i = 1; i <= m; ++i) {
    if (mt[i]) {
      printf("%d %d\n", mt[i], i);
    }
  }
  return 0;
}