Problem: You are given a bipartite graph G = (U, V, E), U is the set of vertices of the first part, V is the set of vertices of the second part and E is the set of edges. There might be multiple edges.

Let's call some subset of its edges <image> k-covering iff the graph <image> has each of its vertices incident to at least k edges. Minimal k-covering is such a k-covering that the size of the subset <image> is minimal possible.

Your task is to find minimal k-covering for each <image>, where minDegree is the minimal degree of any vertex in graph G.

Input

The first line contains three integers n1, n2 and m (1 ≤ n1, n2 ≤ 2000, 0 ≤ m ≤ 2000) — the number of vertices in the first part, the number of vertices in the second part and the number of edges, respectively.

The i-th of the next m lines contain two integers ui and vi (1 ≤ ui ≤ n1, 1 ≤ vi ≤ n2) — the description of the i-th edge, ui is the index of the vertex in the first part and vi is the index of the vertex in the second part.

Output

For each <image> print the subset of edges (minimal k-covering) in separate line.

The first integer cntk of the k-th line is the number of edges in minimal k-covering of the graph. Then cntk integers follow — original indices of the edges which belong to the minimal k-covering, these indices should be pairwise distinct. Edges are numbered 1 through m in order they are given in the input.

Examples

Input

3 3 7
1 2
2 3
1 3
3 2
3 3
2 1
2 1


Output

0 
3 3 7 4 
6 1 3 6 7 4 5 


Input

1 1 5
1 1
1 1
1 1
1 1
1 1


Output

0 
1 5 
2 4 5 
3 3 4 5 
4 2 3 4 5 
5 1 2 3 4 5 

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
const int N = 4105;
const int M = N * 5;
int head[N], work[N], nxt[M], to[M], cap[M], dis[N], que[N];
int edge_cnt, src, snk, back, front, qsz;
void add_edge(int f, int t, int c) {
  nxt[edge_cnt] = head[f];
  head[f] = edge_cnt;
  to[edge_cnt] = t;
  cap[edge_cnt] = c;
  edge_cnt++;
}
void add_bi_edge(int f, int t, int c) {
  add_edge(f, t, c);
  add_edge(t, f, 0);
}
void init() {
  memset(head, -1, sizeof head);
  edge_cnt = 0;
}
bool bfs() {
  back = front = qsz = 0;
  memset(dis, -1, sizeof dis);
  dis[src] = 0;
  que[qsz++, back++] = src;
  while (qsz) {
    int cur = que[qsz--, front++];
    for (int i = head[cur]; ~i; i = nxt[i]) {
      int t = to[i];
      if (!cap[i] || dis[t] != -1) continue;
      dis[t] = dis[cur] + 1;
      if (t == snk) return 1;
      que[qsz++, back++] = t;
    }
  }
  return 0;
}
int dfs(int u, int flow = 1e9 + 3) {
  if (!flow) return flow;
  if (u == snk) return flow;
  for (int &i = work[u]; i != -1; i = nxt[i]) {
    int v = to[i];
    if (!cap[i] || dis[u] + 1 != dis[v]) continue;
    int f = dfs(v, min(flow, cap[i]));
    if (f) {
      cap[i] -= f;
      cap[i ^ 1] += f;
      return f;
    }
  }
  return 0;
}
long long max_flow() {
  long long ret = 0, flow = 0;
  while (bfs()) {
    memcpy(work, head, sizeof head);
    while (flow = dfs(src)) ret += flow;
  }
  return ret;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  init();
  int n, a, m;
  cin >> n >> a >> m;
  vector<int> in(n + a + 2);
  int u, v;
  for (int i = 0; i < m; i++) {
    cin >> u >> v;
    v += n;
    add_bi_edge(u, v, 1);
    in[u]++, in[v]++;
  }
  src = 0;
  snk = n + a + 1;
  int k = m;
  for (int i = int(1); i <= int(n + a); i++) {
    k = min(k, in[i]);
  }
  cout << 0 << '\n';
  for (int i = int(1); i <= int(n); i++) add_bi_edge(src, i, 0);
  for (int i = int(n + 1); i <= int(n + a); i++) add_bi_edge(i, snk, 0);
  for (int K = int(1); K <= int(k); K++) {
    for (int i = m * 2; i < edge_cnt; i += 2) {
      cap[i]++;
    }
    max_flow();
    vector<int> ans;
    for (int i = 0; i < m * 2; i += 2) {
      if (cap[i] == 0) ans.push_back(i / 2 + 1);
    }
    for (int i = m * 2; i < edge_cnt; i += 2) {
      if (cap[i]) {
        int need = cap[i];
        if (to[i] != snk) {
          for (int id = head[to[i]]; ~id && need; id = nxt[id]) {
            if (cap[id] && to[id] != src) {
              ans.push_back(id / 2 + 1);
              need--;
            }
          }
        } else {
          for (int id = head[to[i ^ 1]]; ~id && need; id = nxt[id]) {
            if (cap[id ^ 1] && to[id] != snk) {
              ans.push_back((id ^ 1) / 2 + 1);
              need--;
            }
          }
        }
      }
    }
    cout << int(ans.size());
    for (int i = 0; i < int(int(ans.size())); i++) cout << " " << ans[i];
    cout << '\n';
  }
  return 0;
}