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 maxn1 = 4e3 + 5, maxn2 = 2e4, inf = 0x3f3f3f3f;
int S, T, cnt = 1, n1, n2, m, head[maxn1], cur[maxn1], d[maxn1], sz1[maxn1],
          sz2[maxn1], mm[maxn1];
struct egde {
  int to, nxt;
  int w;
} E[maxn2];
vector<int> ans[maxn1];
void add(int u, int v, int w) {
  E[++cnt].nxt = head[u];
  E[cnt].to = v;
  E[cnt].w = w;
  head[u] = cnt;
}
int bfs() {
  memset(d, 0, sizeof(d));
  d[S] = 1;
  queue<int> Q;
  Q.push(S);
  while (!Q.empty()) {
    int u = Q.front();
    Q.pop();
    for (int i = head[u]; i; i = E[i].nxt) {
      int v = E[i].to;
      if (d[v] || !E[i].w) continue;
      d[v] = d[u] + 1;
      Q.push(v);
      if (v == T) return 1;
    }
  }
  return 0;
}
int dfs(int u, int in = inf) {
  if (u == T || !in) return in;
  int res = in;
  for (int& i = cur[u]; i; i = E[i].nxt) {
    int v = E[i].to;
    if ((d[v] != d[u] + 1) || !E[i].w) continue;
    int k = dfs(v, min(res, E[i].w));
    if (!k)
      d[v] = 0;
    else
      E[i].w -= k, E[i ^ 1].w += k, res -= k;
    if (!res) break;
  }
  return in - res;
}
int Dinic() {
  int ans = 0;
  while (bfs()) {
    for (int i = 0; i <= n1 + n2 + 1; ++i) cur[i] = head[i];
    ans += dfs(S);
  }
  return ans;
}
int main() {
  scanf("%d%d%d", &n1, &n2, &m);
  int u, v, k = inf;
  S = 0, T = n1 + n2 + 1;
  for (int i = 1; i <= m; ++i) {
    scanf("%d%d", &u, &v);
    sz1[u]++;
    sz2[v]++;
    add(u, n1 + v, 1);
    mm[i] = cnt;
    add(n1 + v, u, 0);
  }
  for (int i = 1; i <= n1; ++i) k = min(k, sz1[i]);
  for (int i = 1; i <= n2; ++i) k = min(k, sz2[i]);
  for (int i = 1; i <= n1; ++i) {
    add(S, i, sz1[i] - k);
    add(i, S, 0);
  }
  for (int i = 1; i <= n2; ++i) {
    add(n1 + i, T, sz2[i] - k);
    add(T, n1 + i, 0);
  }
  for (int i = k; i >= 0; --i) {
    Dinic();
    for (int t = 1; t <= m; ++t) {
      if (!E[mm[t] ^ 1].w) ans[i].push_back(t);
    }
    for (int t = head[S]; t; t = E[t].nxt) {
      E[t].w += 1;
    }
    for (int t = head[T]; t; t = E[t].nxt) {
      E[t ^ 1].w += 1;
    }
  }
  for (int i = 0; i <= k; ++i) {
    printf("%d", ans[i].size());
    for (int j = 0; j < ans[i].size(); ++j) printf(" %d", ans[i][j]);
    printf("\n");
  }
  return 0;
}