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 n1, n2, m, cnt, dgr[2050 << 2], s, t, level[2050 << 2], q[2050 << 4], ans;
int key[2050 << 1][2050 << 1], len[2050 << 2];
set<int> S;
struct node {
  int v, c, id;
  node *next, *rev;
} pool[2050 << 5], *h[2050 << 2], *cur[2050 << 2];
bool bfs() {
  int front = 0, rear = 1;
  memset(level, 0, sizeof(level));
  q[front] = s, level[s] = 1;
  while (front < rear) {
    int u = q[front++];
    if (u == t) return true;
    for (node *p = h[u]; p; p = p->next) {
      if (p->c && !level[p->v]) {
        q[rear++] = p->v;
        level[p->v] = level[u] + 1;
      }
    }
  }
  return false;
}
int dfs(int u, int f) {
  if (u == t) return f;
  int flow = 0, F = 0, Min;
  for (node *&p = cur[u]; p; p = p->next) {
    if (p->c && level[p->v] == level[u] + 1) {
      Min = min(f - flow, p->c);
      F = dfs(p->v, Min);
      if (F > 0 && p->id != 0) {
        if (p->id > 0) {
          if (S.find(p->id) != S.end()) S.erase(p->id);
        } else
          S.insert(-p->id);
      }
      flow += F;
      p->c -= F, p->rev->c += F;
      if (flow == f) return flow;
    }
  }
  return flow;
}
int Dinic() {
  int ret = 0;
  while (bfs()) {
    for (int i = s; i <= t; i++) cur[i] = h[i];
    ret += dfs(s, (1 << 28));
  }
  return ret;
}
inline void addedge(int u, int v, int c, int id) {
  node *p1 = &pool[cnt++], *p2 = &pool[cnt++];
  p1->v = v, p1->c = c, p1->rev = p2, p1->next = h[u], p1->id = id, h[u] = p1;
  p2->v = u, p2->c = 0, p2->rev = p1, p2->next = h[v], p2->id = -id, h[v] = p2;
}
int main() {
  int u, v;
  scanf("%d%d%d", &n1, &n2, &m);
  t = n1 + n2 + 1;
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &u, &v);
    addedge(u, v + n1, 1, i);
    dgr[u]++, dgr[v + n1]++;
    S.insert(i);
  }
  int mindgr = (1 << 28);
  for (int i = 1; i <= n1 + n2; i++) mindgr = min(mindgr, dgr[i]);
  for (int i = 1; i <= n1; i++) addedge(s, i, dgr[i] - mindgr, 0);
  for (int i = n1 + 1; i <= n1 + n2; i++) addedge(i, t, dgr[i] - mindgr, 0);
  ans = Dinic();
  key[mindgr][0] = m - ans;
  for (set<int>::iterator it = S.begin(); it != S.end(); it++)
    key[mindgr][++len[mindgr]] = *it;
  for (int k = mindgr - 1; k >= 0; k--) {
    for (int i = 1; i <= n1; i++) addedge(s, i, 1, 0);
    for (int i = n1 + 1; i <= n2 + n1; i++) addedge(i, t, 1, 0);
    ans += Dinic();
    key[k][0] = m - ans;
    for (set<int>::iterator it = S.begin(); it != S.end(); it++)
      key[k][++len[k]] = *it;
  }
  for (int i = 0; i <= mindgr; i++) {
    for (int j = 0; j <= len[i]; j++) printf("%d ", key[i][j]);
    printf("\n");
  }
  return 0;
}