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 = 1e6;
const int inf = 1e9;
vector<int> Eid[N];
int n, m, cnt, S, T, in[N], out[N], cur[N], d[N];
struct Edge {
  int c, v;
} E[N];
void AddEdge(int x, int y, int c) {
  E[cnt].v = y, E[cnt].c = c;
  Eid[x].push_back(cnt++);
  E[cnt].v = x, E[cnt].c = 0;
  Eid[y].push_back(cnt++);
}
bool BFS() {
  static int Q[N];
  int x, ql, qr;
  for (int i = 0; i <= T; i++) d[i] = -1;
  Q[ql = qr = 0] = S;
  d[S] = 0;
  while (ql <= qr) {
    x = Q[ql++];
    for (int i = 0; i < Eid[x].size(); i++) {
      const Edge &e = E[Eid[x][i]];
      if (e.c && d[e.v] == -1) {
        Q[++qr] = e.v;
        d[e.v] = d[x] + 1;
        if (e.v == T) return 1;
      }
    }
  }
  return 0;
}
int Aug(int x, int a) {
  if (x == T) return a;
  int aug = 0, delta;
  for (int &i = cur[x]; i < Eid[x].size(); i++) {
    Edge &e = E[Eid[x][i]];
    if (e.c && d[e.v] == d[x] + 1) {
      delta = Aug(e.v, min(a, e.c));
      if (delta) {
        e.c -= delta;
        E[Eid[x][i] ^ 1].c += delta;
        aug += delta;
        if (!(a -= delta)) break;
      }
    }
  }
  if (!aug) d[x] = -1;
  return aug;
}
int MaxFlow() {
  int flow = 0;
  while (BFS()) {
    for (int i = 0; i <= T; i++) cur[i] = 0;
    flow += Aug(S, inf);
  }
  return flow;
}
int n1, n2, mn, id[N], deg[N];
vector<int> ans[N];
int main() {
  cin >> n1 >> n2 >> m;
  n = n1 + n2;
  S = 0;
  T = n + 1;
  for (int i = 1; i <= m; ++i) {
    int x, y;
    scanf("%d %d", &x, &y);
    y += n1;
    id[i] = cnt;
    AddEdge(x, y, 1);
    deg[x]++;
    deg[y]++;
  }
  mn = deg[1];
  for (int i = 1; i <= n; ++i) mn = min(mn, deg[i]);
  if (mn == 0) return puts("0");
  for (int i = mn; i >= 0; --i) {
    for (int j = 1; j <= n1; ++j) {
      if (deg[j] > i) {
        AddEdge(S, j, deg[j] - i);
        deg[j] = i;
      }
    }
    for (int j = n1 + 1; j <= n; ++j) {
      if (deg[j] > i) {
        AddEdge(j, T, deg[j] - i);
        deg[j] = i;
      }
    }
    for (int j = 0; j < cnt; j += 2) {
    }
    MaxFlow();
    for (int j = 1; j <= m; ++j) {
      if (E[id[j]].c > 0) ans[i].push_back(j);
    }
  }
  for (int i = 0; i <= mn; ++i) {
    printf("%d ", ans[i].size());
    for (int j : ans[i]) printf("%d ", j);
    printf("\n");
  }
}