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;
int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 3) + (x << 1) + (ch ^ 48);
    ch = getchar();
  }
  return x * f;
}
int n1, n2, m, v[200005], w[200005], nxt[200005], head[200005], id[200005],
    cnt = 1, de[200005], S, T, mindegree = 0x3f3f3f3f, X[200005], Y[200005],
    dep[200005], vis[200005], cur[200005];
vector<int> ans[200005];
void add(int a, int b, int c, int d) {
  v[++cnt] = b;
  w[cnt] = c;
  id[cnt] = d;
  nxt[cnt] = head[a];
  head[a] = cnt;
}
int bfs() {
  memset(dep, 0x3f, sizeof(dep));
  for (int i = S; i <= T; i++) cur[i] = head[i];
  queue<int> q;
  q.push(S);
  dep[S] = 0;
  while (!q.empty()) {
    int c = q.front();
    q.pop();
    vis[c] = 0;
    for (int i = head[c]; i; i = nxt[i]) {
      if (dep[v[i]] > dep[c] + 1 && w[i]) {
        dep[v[i]] = dep[c] + 1;
        if (!vis[v[i]]) {
          q.push(v[i]);
          vis[v[i]] = 1;
        }
      }
    }
  }
  if (dep[T] == 0x3f3f3f3f) return 0;
  return 1;
}
int dfs(int x, int limit) {
  if (x == T || !limit) return limit;
  int flow = 0, rlow;
  for (int i = cur[x]; i; i = nxt[i]) {
    cur[x] = i;
    if (dep[v[i]] == dep[x] + 1 && w[i]) {
      if (rlow = dfs(v[i], min(w[i], limit))) {
        flow += rlow;
        limit -= rlow;
        w[i] -= rlow;
        w[i ^ 1] += rlow;
        if (!limit) break;
      }
    }
  }
  return flow;
}
void Dinic() {
  int maxflow = 0;
  while (bfs()) {
    maxflow += dfs(S, 0x3f3f3f3f);
  }
}
int main() {
  n1 = read();
  n2 = read();
  m = read();
  for (int i = 1; i <= m; i++) {
    X[i] = read();
    Y[i] = read();
    de[X[i]]++;
    de[Y[i] + n1]++;
  }
  S = 0;
  T = n1 + n2 + 1;
  for (int i = 1; i <= n1 + n2; i++) mindegree = min(mindegree, de[i]);
  for (int i = 1; i <= m; i++)
    add(X[i], Y[i] + n1, 1, i), add(Y[i] + n1, X[i], 0, i);
  for (int i = 1; i <= n1; i++)
    add(S, i, de[i] - mindegree, 0), add(i, S, 0, 0);
  for (int i = 1; i <= n2; i++)
    add(i + n1, T, de[i + n1] - mindegree, 0), add(T, i + n1, 0, 0);
  for (int i = mindegree; i >= 0; i--) {
    Dinic();
    for (int j = 1; j <= n1; j++)
      for (int k = head[j]; k; k = nxt[k])
        if (w[k] && id[k]) ans[i].push_back(id[k]);
    for (int j = head[S]; j; j = nxt[j]) w[j]++;
    for (int j = head[T]; j; j = nxt[j]) w[j ^ 1]++;
  }
  for (int i = 0; i <= mindegree; i++) {
    int siz = ans[i].size();
    printf("%d ", siz);
    for (int j = 0; j < siz; j++) printf("%d ", ans[i][j]);
    puts("");
  }
}