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 maxn = 5555;
int first[maxn], sign, cur[maxn];
int s, t, d[maxn];
struct node {
  int to, w, next, id;
} edge[maxn * 50];
void creat() {
  memset(first, -1, sizeof(first));
  sign = 0;
}
void add_edge(int u, int v, int w, int id) {
  edge[sign].to = v;
  edge[sign].w = w;
  edge[sign].id = id;
  edge[sign].next = first[u];
  first[u] = sign++;
  edge[sign].to = u;
  edge[sign].w = 0;
  edge[sign].next = first[v];
  first[v] = sign++;
}
int bfs() {
  queue<int> q;
  memset(d, 0, sizeof(d));
  d[s] = 1;
  q.push(s);
  while (!q.empty()) {
    int top = q.front();
    q.pop();
    for (int i = first[top]; ~i; i = edge[i].next) {
      int to = edge[i].to;
      if (edge[i].w > 0 && d[to] == 0) {
        d[to] = d[top] + 1;
        if (to == t) return 1;
        q.push(to);
      }
    }
  }
  return d[t] != 0;
}
int dfs(int top, int flow) {
  if (top == t) return flow;
  int ans = 0, x = 0;
  for (int i = cur[top]; ~i; i = edge[i].next) {
    int to = edge[i].to;
    if (edge[i].w > 0 && d[to] == d[top] + 1) {
      x = dfs(to, min(flow - ans, edge[i].w));
      edge[i].w -= x;
      edge[i ^ 1].w += x;
      if (edge[i].w) cur[top] = i;
      ans += x;
      if (ans == flow) return flow;
    }
  }
  if (ans == 0) d[top] = 0;
  return ans;
}
int dinic(int n) {
  int ans = 0;
  while (bfs()) {
    for (int i = 0; i <= n; i++) cur[i] = first[i];
    ans += dfs(s, 0x3fffffff);
  }
  return ans;
}
int dn1[maxn], dn2[maxn];
vector<int> as[maxn];
int main() {
  int n1, n2, m;
  scanf("%d%D%d", &n1, &n2, &m);
  creat();
  s = 0, t = n1 + n2 + 1;
  for (int i = 1; i <= m; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    dn1[x]++, dn2[y]++;
    add_edge(x, n1 + y, 1, i);
  }
  int mxk = 0x3fffffff;
  for (int i = 1; i <= n1; i++) {
    mxk = min(mxk, dn1[i]);
  }
  for (int i = 1; i <= n2; i++) {
    mxk = min(mxk, dn2[i]);
  }
  for (int i = 1; i <= n1; i++) add_edge(s, i, dn1[i] - mxk, 0);
  for (int i = 1; i <= n2; i++) add_edge(n1 + i, t, dn2[i] - mxk, 0);
  int ans = 0;
  for (int k = mxk; k >= 0; k--) {
    dinic(t);
    for (int i = 0; i < sign; i++) {
      if (edge[i].id && edge[i].w == 1) as[k].push_back(edge[i].id);
    }
    for (int i = first[s]; ~i; i = edge[i].next) {
      edge[i].w++;
    }
    for (int i = first[t]; ~i; i = edge[i].next) {
      edge[i ^ 1].w++;
    }
  }
  for (int i = 0; i <= mxk; i++) {
    printf("%d", as[i].size());
    for (int j = 0; j < as[i].size(); j++) printf(" %d", as[i][j]);
    puts("");
  }
}