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;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
const int MAXN = 2000;
const int MAXM = 2000;
int n1, n2, m;
vector<int> ladj[MAXN], radj[MAXN];
const int GMAXN = 2 * MAXN + 2;
const int GMAXM = MAXM + 2 * MAXN;
struct G {
  int n, m;
  int ghead[GMAXN], gnxt[2 * GMAXM], gto[2 * GMAXM], gcap[2 * GMAXM];
  void init(int _n) {
    n = _n;
    m = 0;
    for (int i = (0); i < (n); ++i) ghead[i] = -1;
  }
  int addedge(int a, int b, int c) {
    int ret = m;
    gnxt[m] = ghead[a];
    ghead[a] = m;
    gto[m] = b;
    gcap[m] = c;
    ++m;
    gnxt[m] = ghead[b];
    ghead[b] = m;
    gto[m] = a;
    gcap[m] = 0;
    ++m;
    return ret;
  }
  int back[MAXN], flow[MAXN], q[MAXN], qhead, qtail;
  int mf(int s, int t) {
    int ret = 0;
    while (true) {
      for (int i = (0); i < (n); ++i) back[i] = -1, flow[i] = 0;
      qhead = qtail = 0;
      flow[s] = INT_MAX;
      q[qhead++] = s;
      while (qtail < qhead) {
        int at = q[qtail++];
        for (int x = ghead[at]; x != -1; x = gnxt[x])
          if (gcap[x] != 0) {
            int to = gto[x];
            if (flow[to] != 0) continue;
            flow[to] = min(flow[at], gcap[x]);
            back[to] = x ^ 1;
            q[qhead++] = to;
          }
      }
      if (flow[t] == 0)
        return ret;
      else
        ret += flow[t];
      for (int x = t; x != s; x = gto[back[x]]) {
        gcap[back[x]] += flow[t];
        gcap[back[x] ^ 1] -= flow[t];
      }
    }
  }
};
G g;
int e[MAXM][2];
int eid1[MAXN], eid2[MAXN], eid3[MAXM];
bool use[MAXM];
int cnt1[MAXN], cnt2[MAXN];
void run() {
  scanf("%d%d%d", &n1, &n2, &m);
  for (int i = (0); i < (m); ++i) {
    int a, b;
    scanf("%d%d", &a, &b);
    --a, --b;
    e[i][0] = a, e[i][1] = b;
    ladj[a].push_back(b);
    radj[b].push_back(a);
  }
  int dmin = INT_MAX;
  for (int i = (0); i < (n1); ++i) dmin = min(dmin, ((int)(ladj[i]).size()));
  for (int i = (0); i < (n2); ++i) dmin = min(dmin, ((int)(radj[i]).size()));
  g.init(2 + n1 + n2);
  int s = n1 + n2, t = n1 + n2 + 1;
  for (int i = (0); i < (n1); ++i) eid1[i] = g.addedge(s, i, 0);
  for (int i = (0); i < (n2); ++i) eid2[i] = g.addedge(n1 + i, t, 0);
  for (int i = (0); i < (m); ++i) eid3[i] = g.addedge(e[i][0], n1 + e[i][1], 1);
  for (int k = (0); k <= (dmin); ++k) {
    int extraflow = g.mf(s, t);
    for (int i = (0); i < (m); ++i) use[i] = g.gcap[eid3[i]] == 0;
    for (int i = (0); i < (n1); ++i) cnt1[i] = 0;
    for (int i = (0); i < (n2); ++i) cnt2[i] = 0;
    for (int i = (0); i < (m); ++i)
      if (use[i]) ++cnt1[e[i][0]], ++cnt2[e[i][1]];
    for (int i = (0); i < (m); ++i)
      if (cnt1[e[i][0]] < k || cnt2[e[i][1]] < k)
        use[i] = true, cnt1[e[i][0]]++, cnt2[e[i][1]]++;
    int nuse = 0;
    for (int i = (0); i < (m); ++i)
      if (use[i]) ++nuse;
    printf("%d", nuse);
    for (int i = (0); i < (m); ++i)
      if (use[i]) printf(" %d", i + 1);
    puts("");
    for (int i = (0); i < (n1); ++i) ++g.gcap[eid1[i]];
    for (int i = (0); i < (n2); ++i) ++g.gcap[eid2[i]];
  }
}
int main() {
  run();
  return 0;
}