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 = 2002, M = 100002;
int n1, n2, m, deg[2 * N], src, sink;
pair<int, int> a[N];
struct edge {
  int u, v;
  int cap, flow;
  int next;
  int idx;
} E[M];
int n, e, last[M], Last[M], d[M], q[M], first, l;
bool getPath(int src, int sink) {
  q[first = l = 0] = src;
  for (int i = 0; i < n; ++i) d[i] = -1;
  d[src] = 0;
  while (first <= l) {
    src = q[first];
    ++first;
    for (int e = last[src]; e != -1; e = E[e].next)
      if (d[E[e].v] == -1 && E[e].flow < E[e].cap) {
        d[E[e].v] = d[src] + 1;
        q[++l] = E[e].v;
      }
  }
  return d[sink] != -1;
}
int DFS(int u, int flow) {
  if (u == n - 1) return flow;
  for (int &e = Last[u], r; e != -1; e = E[e].next)
    if (E[e].flow < E[e].cap && d[E[e].v] == d[u] + 1) {
      r = DFS(E[e].v, min(flow, E[e].cap - E[e].flow));
      if (r > 0) {
        E[e].flow += r;
        E[e ^ 1].flow -= r;
        return r;
      }
    }
  return 0;
}
int maxFlow(int src, int sink) {
  int MaxFlow = 0;
  int flow;
  while (getPath(src, sink)) {
    for (int i = 0; i < n; ++i) Last[i] = last[i];
    while (flow = DFS(src, 1000000000)) MaxFlow += flow;
  }
  return MaxFlow;
}
void addEdge(int a, int b, int c, int idx) {
  E[e].u = a, E[e].v = b;
  E[e].cap = c, E[e].flow = 0;
  E[e].next = last[a], E[e].idx = idx;
  last[a] = e++;
  E[e].u = b, E[e].v = a;
  E[e].cap = 0, E[e].flow = 0;
  E[e].next = last[b], E[e].idx = idx;
  last[b] = e++;
}
inline void rebuild(int k) {
  e = 0;
  memset(last, -1, sizeof last);
  for (int i = 1; i <= m; ++i) addEdge(a[i].first, a[i].second + n1, 1, i);
  for (int i = 1; i <= n1; ++i) addEdge(src, i, deg[i] - k, 0);
  for (int i = n1 + 1; i <= n1 + n2; ++i) addEdge(i, sink, deg[i] - k, 0);
}
int main() {
  scanf("%d%d%d", &n1, &n2, &m);
  for (int i = 1; i <= m; ++i) {
    scanf("%d%d", &a[i].first, &a[i].second);
    ++deg[a[i].first];
    ++deg[a[i].second + n1];
  }
  src = 0;
  sink = n1 + n2 + 1;
  n = sink + 1;
  int mn = *min_element(deg + 1, deg + 1 + n1 + n2);
  puts("0");
  for (int i = 1; i <= mn; ++i) {
    rebuild(i);
    maxFlow(src, sink);
    vector<int> ans;
    for (int j = 0; j <= e - 1; ++j)
      if (E[j].u <= n1 and E[j].idx and !E[j].flow) ans.push_back(E[j].idx);
    printf("%d", ((int)(ans).size()));
    for (int j : ans) printf(" %d", j);
    puts("");
  }
}