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 = 4100, INF = 0x3f3f3f3f;
int n1, n2, m, sz, cost, cnt, d[N], lv[N], q[N], cur[N], hd[N];
struct edge {
  int v, f, nxt;
} e[N * 5];
void adde(int u, int v, int f) { e[++cnt] = (edge){v, f, hd[u]}, hd[u] = cnt; }
void adde2(int u, int v, int f) { adde(u, v, f), adde(v, u, 0); }
bool bfs(int S, int T) {
  memset(lv, 0, sz), lv[S] = 1;
  int h = 0, t = 0;
  q[t++] = S;
  while (h < t) {
    int u = q[h++];
    for (int i = hd[u], v; i; i = e[i].nxt) {
      if (!e[i].f || lv[v = e[i].v]) continue;
      lv[v] = lv[u] + 1, q[t++] = v;
      if (v == T) return 1;
    }
  }
  return 0;
}
int dfs(int u, int mx, int T) {
  if (u == T) return mx;
  int ret = 0;
  for (int &i = cur[u], v; i; i = e[i].nxt) {
    if (!e[i].f || lv[v = e[i].v] != lv[u] + 1) continue;
    int f = dfs(v, min(e[i].f, mx - ret), T);
    e[i].f -= f, e[i ^ 1].f += f, ret += f;
    if (ret == mx) break;
  }
  return ret;
}
int dinic(int S, int T) {
  static int ret;
  while (bfs(S, T)) memcpy(cur, hd, sz), ret += dfs(S, INF, T);
  return ret;
}
int main() {
  int S, T, SS, TT;
  cnt = 1;
  cin >> n1 >> n2 >> m;
  S = 0, T = n1 + n2 + 1, SS = T + 1, TT = SS + 1;
  sz = 4 * (TT + 1);
  for (int i = 1, u, v; i <= m; i++) {
    scanf("%d%d", &u, &v);
    adde2(u, v + n1, 1);
    d[u]++, d[v + n1]++;
  }
  int cnts = cnt + 1, cntt = cnt + 3;
  adde2(S, TT, 0), adde2(SS, T, 0);
  for (int i = 1; i <= n1; i++) adde2(S, i, INF), adde2(SS, i, 0);
  for (int i = 1; i <= n2; i++) adde2(i + n1, T, INF), adde2(i + n1, TT, 0);
  int cntst = cnt + 1;
  adde2(T, S, INF);
  int mnd = 1e9;
  for (int i = 1; i <= n1 + n2; i++) mnd = min(mnd, d[i]);
  puts("0");
  for (int i = 1; i <= mnd; i++) {
    for (int j = hd[SS]; j; j = e[j].nxt)
      if (e[j].v != T) e[j].f++;
    for (int j = hd[TT]; j; j = e[j].nxt)
      if (e[j].v != S) e[j ^ 1].f++;
    e[cnts].f += n1, e[cntt].f += n2;
    int pre = e[cntst].f;
    e[cntst].f = e[cntst ^ 1].f = 0;
    dinic(SS, TT);
    e[cntst].f = pre, e[cntst ^ 1].f = INF - pre;
    dinic(SS, TT);
    int c = 0;
    for (int j = 1; j <= m; j++)
      if (!e[j << 1].f) c++;
    printf("%d", c);
    for (int j = 1; j <= m; j++)
      if (!e[j << 1].f) printf(" %d", j);
    putchar('\n');
  }
  return 0;
}