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;
unordered_map<
    long long,
    unordered_map<long long, pair<pair<long long, long long>, long long> > >
    inpmt;
vector<long long> dcp;
void SieveOfErat() {
  bool prime[1000001];
  memset(prime, true, sizeof(prime));
  for (long long vec = 2; vec * vec <= 1000000; vec++) {
    if (prime[vec] == true) {
      for (long long dd = vec * 2; dd <= 1000000; dd += vec) prime[dd] = false;
    }
  }
}
long long gcd(long long aa, long long id2) {
  if (aa == 0) {
    return id2;
  } else
    return gcd(aa % id2, id2);
}
struct vect {
  struct vect *foll;
  long long calc;
  struct vect *succ;
};
int an[5050][5050], degree[5050], ff[5050][5050];
vector<int> graph[5050], vasl[5050], res[5050];
int n1, n2, m, source, sink, v[5050], cc;
int flow(int a) {
  if (a == sink) return 1;
  v[a] = cc;
  for (auto &x : graph[a]) {
    if (v[x] != cc && an[a][x]) {
      if (flow(x)) {
        an[a][x]--;
        an[x][a]++;
        return 1;
      }
    }
  }
  return 0;
}
int main() {
  int i, a, b, j;
  cin >> n1 >> n2 >> m;
  sink = n1 + n2 + 1;
  for (i = 0; i < m; i++) {
    cin >> a >> b;
    b += n1;
    an[a][b]++;
    graph[a].push_back(b);
    graph[b].push_back(a);
    vasl[a].push_back(i + 1);
    vasl[b].push_back(i + 1);
    degree[a]++, degree[b]++;
  }
  int minn = 1e9;
  for (i = 1; i <= n1 + n2; i++) minn = min(minn, degree[i]);
  for (i = 1; i <= n1; i++) {
    graph[0].push_back(i), graph[i].push_back(0);
    an[0][i] = degree[i] - minn;
  }
  for (i = n1 + 1; i <= n1 + n2; i++) {
    graph[sink].push_back(i), graph[i].push_back(sink);
    an[i][sink] = degree[i] - minn;
  }
  for (int tt = 0; tt <= minn; tt++) {
    cc++;
    while (flow(0)) {
      cc++;
    }
    for (i = 1; i <= n1; i++) {
      for (auto &t : graph[i]) ff[i][t] = an[i][t];
    }
    for (i = 1; i <= n1; i++) {
      for (j = 0; j < graph[i].size(); j++) {
        int x = graph[i][j];
        if (x && ff[i][x]) {
          ff[i][x]--;
          res[minn - tt].push_back(vasl[i][j]);
        }
      }
    }
    for (i = 1; i <= n1; i++) an[0][i]++;
    for (i = n1 + 1; i <= n1 + n2; i++) an[i][sink]++;
  }
  for (i = 0; i <= minn; i++) {
    printf("%d ", res[i].size());
    for (auto &t : res[i]) printf("%d ", t);
    puts("");
  }
}