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 ned, prv[103000], first[103000];
int cap[900000], to[900000], nxt[900000], dist[103000];
void init() {
  memset(first, -1, sizeof first);
  ned = 0;
}
void add(int u, int v, int f) {
  to[ned] = v, cap[ned] = f;
  nxt[ned] = first[u];
  first[u] = ned++;
  to[ned] = u, cap[ned] = 0;
  nxt[ned] = first[v];
  first[v] = ned++;
}
int augment(int v, int minEdge, int s) {
  int e = prv[v];
  if (e == -1) return minEdge;
  int f = augment(to[e ^ 1], min(minEdge, cap[e]), s);
  cap[e] -= f;
  cap[e ^ 1] += f;
  return f;
}
bool bfs(int s, int t) {
  int u, v;
  memset(&dist, -1, sizeof dist);
  dist[s] = 0;
  queue<int> q;
  q.push(s);
  memset(&prv, -1, sizeof prv);
  while (!q.empty()) {
    u = q.front();
    q.pop();
    if (u == t) break;
    for (int e = first[u]; e != -1; e = nxt[e]) {
      v = to[e];
      if (dist[v] < 0 && cap[e] > 0) {
        dist[v] = dist[u] + 1;
        q.push(v);
        prv[v] = e;
      }
    }
  }
  return dist[t] >= 0;
}
int edmondskarp(int s, int t) {
  int result = 0;
  while (bfs(s, t)) {
    result += augment(t, (1 << 30), s);
  }
  return result;
}
int degu[103000], degv[103000], mindeg;
int n1, n2, m, eu[103000], ev[103000], edu[103000], edv[103000], edt[103000];
vector<vector<int> > ans;
void solve() {
  int s = 0;
  int t = n1 + n2 + 1;
  init();
  memset(&degu, 0, sizeof degu);
  memset(&degv, 0, sizeof degv);
  for (int j = 1; (j) <= (m); (j)++) {
    add(eu[j], ev[j] + n1, 1);
    edt[j] = ned - 2;
    degu[eu[j]]++;
    degv[ev[j]]++;
  }
  mindeg = (1 << 30);
  for (int u = 1; (u) <= (n1); (u)++) mindeg = min(mindeg, degu[u]);
  for (int v = 1; (v) <= (n2); (v)++) mindeg = min(mindeg, degv[v]);
  for (int u = 1; (u) <= (n1); (u)++) {
    add(s, u, degu[u] - mindeg);
    edu[u] = ned - 2;
  }
  for (int v = 1; (v) <= (n2); (v)++) {
    add(n1 + v, t, degv[v] - mindeg);
    edv[v] = ned - 2;
  }
  ans.resize(mindeg + 1);
  for (int k = mindeg; k >= 0; k--) {
    edmondskarp(s, t);
    for (int j = 1; (j) <= (m); (j)++) {
      if (cap[edt[j]]) ans[k].push_back(j);
    }
    sort(ans[k].begin(), ans[k].end());
    for (int u = 1; (u) <= (n1); (u)++) {
      cap[edu[u]]++;
    }
    for (int v = 1; (v) <= (n2); (v)++) {
      cap[edv[v]]++;
    }
  }
}
void print() {
  for (auto v : ans) {
    printf("%u", v.size());
    for (int j : v) {
      printf(" %d", j);
    }
    printf("\n");
  }
}
void read() {
  scanf("%d %d %d", &n1, &n2, &m);
  for (int j = 1; (j) <= (m); (j)++) {
    scanf("%d %d", &eu[j], &ev[j]);
  }
}
int main() {
  read();
  solve();
  print();
  return 0;
}