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 = 20005;
const int mxN = N, mxM = N, INF = 0x3f3f3f3f;
struct graph {
  int S, T;
  int base[mxN], vec[mxM], pre[mxM], tot;
  int c[mxM];
  int d[mxN], q[mxN];
  bool vis[mxN];
  void init() {
    memset(base, 0, sizeof(base));
    tot = 1;
  }
  int link(int x, int y, int z) {
    vec[++tot] = y;
    pre[tot] = base[x];
    base[x] = tot;
    c[tot] = z;
    vec[++tot] = x;
    pre[tot] = base[y];
    base[y] = tot;
    c[tot] = 0;
    return tot - 1;
  }
  bool bfs() {
    int head = 0, tail = 0;
    memset(d, -1, sizeof(d));
    d[S] = 0;
    q[++tail] = S;
    while (head < tail) {
      head++;
      int u = q[head];
      for (int now = base[u]; now; now = pre[now]) {
        int v = vec[now];
        if (d[v] == -1 && c[now] > 0) {
          d[v] = d[u] + 1;
          q[++tail] = v;
          if (v == T) return 1;
        }
      }
    }
    return 0;
  }
  int dfs(int u, int flow) {
    int r = 0;
    if (u == T) return flow;
    for (int now = base[u]; now && r < flow; now = pre[now]) {
      int v = vec[now];
      if (c[now] > 0 && d[v] == d[u] + 1) {
        int x = min(c[now], flow - r);
        x = dfs(v, x);
        r += x;
        c[now] -= x;
        c[now ^ 1] += x;
      }
    }
    if (!r) d[u] = -2;
    return r;
  }
  int dinic() {
    int ans = 0;
    while (bfs()) ans += dfs(S, INF);
    return ans;
  }
} G;
int eid[N];
int mem[N];
int du[N];
vector<int> ans[N];
int main() {
  G.init();
  int n1, n2, m;
  scanf("%d%d%d", &n1, &n2, &m);
  for (int i = 1; i <= m; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    eid[i] = G.link(x, n1 + y, 1);
    du[x]++;
    du[n1 + y]++;
  }
  G.S = 0;
  G.T = n1 + n2 + 1;
  int top = N;
  for (int i = 1; i <= n1 + n2; i++) top = min(top, du[i]);
  for (int i = 1; i <= n1; i++) mem[i] = G.link(G.S, i, du[i] - top);
  for (int i = n1 + 1; i <= n1 + n2; i++) mem[i] = G.link(i, G.T, du[i] - top);
  printf("0\n");
  for (int k = top; k >= 1; k--) {
    G.dinic();
    for (int i = 1; i <= m; i++)
      if (G.c[eid[i]]) ans[k].push_back(i);
    for (int i = 1; i <= n1 + n2; i++) G.c[mem[i]]++;
  }
  for (int i = 1; i <= top; i++) {
    printf("%d", ans[i].size());
    for (int v : ans[i]) printf(" %d", v);
    printf("\n");
  }
}