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 int nmax = 2000 + 5;
int fol[nmax + 1], viz[nmax + 1];
int n, m;
int l[nmax + 1], r[nmax + 1], muchie[nmax + 1];
int grdr[nmax + 1], grst[nmax + 1];
vector<pair<int, int> > g[nmax + 1], gdr[nmax + 1];
bool pair_up(int nod, int lim) {
  if (viz[nod] == 1) return 0;
  viz[nod] = 1;
  for (auto i : g[nod]) {
    if (fol[i.second] == 0 && l[i.first] == 0 && grdr[i.first] < lim) {
      l[i.first] = nod;
      r[nod] = i.first;
      muchie[nod] = i.second;
      return 1;
    }
  }
  for (auto i : g[nod]) {
    if (fol[i.second] == 0 && grdr[i.first] < lim && pair_up(l[i.first], lim)) {
      l[i.first] = nod;
      r[nod] = i.first;
      muchie[nod] = i.second;
      return 1;
    }
  }
  return 0;
}
void cuplaj(int pas) {
  memset(l, 0, sizeof(l));
  memset(r, 0, sizeof(r));
  memset(muchie, 0, sizeof(muchie));
  bool ok = 1;
  int ans = 0;
  while (ok) {
    ok = 0;
    memset(viz, 0, sizeof(viz));
    for (int i = 1; i <= n; ++i) {
      if (grst[i] < pas && r[i] == 0 && pair_up(i, pas)) {
        ++ans;
        ok = 1;
      }
    }
  }
}
int main() {
  int nrm;
  fscanf(stdin, "%d%d%d", &n, &m, &nrm);
  for (int i = 1; i <= nrm; ++i) {
    int x, y;
    fscanf(stdin, "%d%d", &x, &y);
    g[x].push_back({y, i});
    gdr[y].push_back({x, i});
    ++grdr[y];
  }
  int mndeg = 1 << 30;
  srand(time(0));
  for (int i = 1; i <= n; ++i) {
    mndeg = min(mndeg, (int)g[i].size());
    random_shuffle(g[i].begin(), g[i].end());
  }
  for (int i = 1; i <= m; ++i) {
    mndeg = min(mndeg, grdr[i]);
    grdr[i] = 0;
  }
  fprintf(stdout, "0\n");
  vector<int> sol;
  for (int pas = 1; pas <= mndeg; ++pas) {
    cuplaj(pas);
    for (int i = 1; i <= n; ++i) {
      if (muchie[i] > 0) {
        sol.push_back(muchie[i]);
        fol[muchie[i]] = 1;
        ++grst[i];
        ++grdr[r[i]];
      }
    }
    for (int j = 1; j <= m; ++j) {
      if (l[j] > 0 || grdr[j] >= pas) continue;
      for (auto i : gdr[j]) {
        if (fol[i.second] == 1) continue;
        ++grst[i.first];
        ++grdr[j];
        sol.push_back(i.second);
        fol[i.second] = 1;
        break;
      }
    }
    for (int j = 1; j <= n; ++j) {
      if (grst[j] >= pas) continue;
      for (auto i : g[j]) {
        if (fol[i.second] == 1) continue;
        ++grst[j];
        ++grdr[i.first];
        sol.push_back(i.second);
        fol[i.second] = 1;
        break;
      }
    }
    fprintf(stdout, "%d ", (int)sol.size());
    for (auto i : sol) fprintf(stdout, "%d ", i);
    fprintf(stdout, "\n");
  }
  return 0;
}