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 long long oo = 1e18;
const int N = 20005, E = 300006;
vector<int> g[N];
int ne;
struct Edge {
  int from, to;
  long long cap;
} edge[E];
int lvl[N], vis[N], pass, source, target, px[N];
long long run(int s, long long minE) {
  if (s == target) {
    return minE;
  }
  long long ans = 0;
  for (; px[s] < (int)g[s].size(); px[s]++) {
    int e = g[s][px[s]];
    auto &v = edge[e], &rev = edge[e ^ 1];
    if (lvl[v.to] != lvl[s] + 1 || v.cap <= 0) continue;
    long long tmp = run(v.to, min(minE, v.cap));
    v.cap -= tmp, rev.cap += tmp;
    ans += tmp, minE -= tmp;
    if (minE == 0) break;
  }
  return ans;
}
int bfs() {
  queue<int> q;
  q.push(source);
  lvl[source] = 1;
  vis[source] = ++pass;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    px[u] = 0;
    for (int e : g[u]) {
      auto v = edge[e];
      if (v.cap <= 0 || vis[v.to] == pass) continue;
      vis[v.to] = pass;
      lvl[v.to] = lvl[u] + 1;
      q.push(v.to);
    }
  }
  return vis[target] == pass;
}
long long flow() {
  long long ans = 0;
  while (bfs()) ans += run(source, oo);
  return ans;
}
void addEdge(int u, int v, long long c) {
  edge[ne] = {u, v, c};
  g[u].push_back(ne++);
  edge[ne] = {v, u, 0};
  g[v].push_back(ne++);
}
int in[N];
int main() {
  int n1, n2, m;
  source = N - 1, target = N - 2;
  scanf("%d %d %d", &n1, &n2, &m);
  for (int i = 0; i < m; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    a--, b--;
    in[a]++, in[n1 + b]++;
    b += n1;
    addEdge(a, b, 1);
  }
  int k = m;
  for (int i = 0; i < n1; i++) k = min(k, in[i]);
  for (int i = 0; i < n2; i++) k = min(k, in[i + n1]);
  int em = ne;
  for (int i = 0; i < n1; i++) addEdge(source, i, in[i] - k - 1);
  int e1 = ne;
  for (int i = 0; i < n2; i++) addEdge(n1 + i, target, in[n1 + i] - k - 1);
  int e2 = ne;
  vector<vector<int> > ans;
  for (; k >= 0; k--) {
    for (int i = em; i < e2; i += 2) edge[i].cap++;
    flow();
    vector<int> tmp;
    for (int i = 0; i < em; i += 2)
      if (edge[i].cap) tmp.push_back(i / 2 + 1);
    ans.emplace_back(move(tmp));
  }
  for (int i = (int)ans.size() - 1; i >= 0; i--) {
    printf("%d", (int)ans[i].size());
    for (int x : ans[i]) printf(" %d", x);
    printf("\n");
  }
}