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;
struct Flux {
  struct muchie {
    int x, flx, cap, indop;
    muchie() {}
    muchie(int _x, int _flx, int _cap, int _indop) {
      x = _x, flx = _flx, cap = _cap, indop = _indop;
    }
  };
  int S, D;
  vector<muchie> e;
  vector<int> mind;
  vector<vector<int> > g;
  vector<int> tata, intra;
  void init(int _S, int _D) {
    S = _S;
    D = _D;
    g.resize(D + 1);
  }
  void trage_muchie(int x, int y, int cap, int ind) {
    g[x].push_back((int)e.size());
    mind.push_back(ind);
    e.push_back(muchie(y, 0, cap, (int)e.size() + 1));
    g[y].push_back((int)e.size());
    mind.push_back(0);
    e.push_back(muchie(x, 0, 0, (int)e.size() - 1));
  }
  bool bfs() {
    tata = vector<int>(D + 1, -1);
    intra = vector<int>(D + 1, -1);
    queue<int> q;
    q.push(S);
    tata[S] = 0;
    while (!q.empty()) {
      int x = q.front();
      q.pop();
      for (auto i : g[x]) {
        if (e[i].flx < e[i].cap && tata[e[i].x] == -1) {
          tata[e[i].x] = x;
          intra[e[i].x] = i;
          q.push(e[i].x);
        }
      }
    }
    return tata[D] != -1;
  }
  int max_flow() {
    int ans = 0;
    while (bfs()) {
      for (auto i : g[D]) {
        int ind = e[i].indop;
        if (tata[e[i].x] != -1 && e[ind].flx < e[ind].cap) {
          int flmin = e[ind].cap - e[ind].flx;
          for (int x = e[i].x; x != S; x = tata[x])
            flmin = min(flmin, e[intra[x]].cap - e[intra[x]].flx);
          ans += flmin;
          e[ind].flx += flmin;
          e[i].flx -= flmin;
          for (int x = e[i].x; x != S; x = tata[x]) {
            e[intra[x]].flx += flmin;
            e[e[intra[x]].indop].flx -= flmin;
          }
        }
      }
    }
    return ans;
  }
} F;
int main() {
  int nrm, n, m;
  fscanf(stdin, "%d%d%d", &n, &m, &nrm);
  vector<int> grdr(m + 1, 0), grst(n + 1, 0);
  F.init(n + m + 1, n + m + 2);
  for (int i = 1; i <= nrm; ++i) {
    int x, y;
    fscanf(stdin, "%d%d", &x, &y);
    ++grst[x];
    ++grdr[y];
    F.trage_muchie(x, n + y, 1, i);
  }
  int mndeg = 1 << 30;
  for (int i = 1; i <= n; ++i) {
    mndeg = min(mndeg, grst[i]);
  }
  for (int i = 1; i <= m; ++i) {
    mndeg = min(mndeg, grdr[i]);
  }
  for (int i = 1; i <= n; ++i) F.trage_muchie(F.S, i, grst[i] - mndeg, -1);
  for (int i = 1; i <= m; ++i) F.trage_muchie(n + i, F.D, grdr[i] - mndeg, -1);
  vector<vector<int> > sol(mndeg + 1);
  for (int pas = mndeg; pas >= 0; --pas) {
    F.max_flow();
    for (int i = 0; i < 2 * nrm; i += 2) {
      if (F.e[i].cap > F.e[i].flx) sol[pas].push_back(F.mind[i]);
    }
    for (int i = 2 * nrm; i < (int)F.e.size(); i += 2) {
      ++F.e[i].cap;
    }
  }
  for (auto &i : sol) {
    fprintf(stdout, "%d ", (int)i.size());
    for (auto &j : i) {
      fprintf(stdout, "%d ", j);
    }
    fprintf(stdout, "\n");
  }
  return 0;
}