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;
void minimize(int &a, int b) { a = min(a, b); }
const int limit = 7000;
vector<int> g[limit];
short int capacity[limit][limit];
int previous[limit];
int arrives[limit];
int ini, fin;
int tiempo;
int increment() {
  tiempo++;
  queue<int> q;
  q.push(ini);
  arrives[ini] = tiempo;
  while (not q.empty()) {
    int u = q.front();
    q.pop();
    vector<int> &ar = g[u];
    for (int i = 0; i < int(ar.size()); i++) {
      int v = ar[i];
      if (arrives[v] != tiempo and capacity[u][v]) {
        arrives[v] = tiempo;
        previous[v] = u;
        q.push(v);
        if (v == fin) {
          while (v != ini) {
            int antv = previous[v];
            capacity[antv][v]--;
            capacity[v][antv]++;
            v = antv;
          }
          return 1;
        }
      }
    }
  }
  return 0;
}
void maxflow() {
  int f = 0;
  for (;;) {
    int a = increment();
    if (a == 0) break;
    f += a;
  }
}
void add(int u, int v) {
  g[u].push_back(v);
  g[v].push_back(u);
  capacity[u][v]++;
}
void adddir(int u, int v) { g[u].push_back(v); }
int n1, n2, m;
int au[limit];
int av[limit];
int du[limit];
int dv[limit];
int degu[limit];
int degv[limit];
int used[limit];
vector<int> listu[limit];
vector<int> listv[limit];
int main() {
  ios::sync_with_stdio(false);
  cin >> n1 >> n2 >> m;
  for (int i = 1; i <= m; i++) {
    cin >> au[i] >> av[i];
    add(m + au[i], i);
    add(i, m + n1 + av[i]);
    du[au[i]]++;
    dv[av[i]]++;
    listu[au[i]].push_back(i);
    listv[av[i]].push_back(i);
  }
  int mindeg = m;
  for (int i = 1; i <= n1; i++) minimize(mindeg, du[i]);
  for (int i = 1; i <= n2; i++) minimize(mindeg, dv[i]);
  ini = m + n1 + n2 + 1;
  fin = ini + 1;
  for (int i = 1; i <= n1; i++) adddir(ini, m + i);
  for (int i = 1; i <= n2; i++) adddir(m + n1 + i, fin);
  for (int deg = 0; deg <= mindeg; deg++) {
    maxflow();
    for (int i = 1; i <= m; i++) used[i] = 0;
    for (int i = 1; i <= n1; i++) degu[i] = 0;
    for (int i = 1; i <= n2; i++) degv[i] = 0;
    vector<int> sol;
    for (int i = 1; i <= m; i++) {
      if (capacity[i][m + n1 + av[i]] == 0) {
        sol.push_back(i);
        degu[au[i]]++;
        degv[av[i]]++;
        used[i] = 1;
      }
    }
    for (int i = 1; i <= n1; i++) capacity[ini][m + i]++;
    for (int i = 1; i <= n2; i++) capacity[m + n1 + i][fin]++;
    for (int u = 1; u <= n1; u++) {
      vector<int> lu = listu[u];
      for (int i = 0; i < int(lu.size()) and degu[u] < deg; i++) {
        int ia = lu[i];
        if (not used[ia]) {
          sol.push_back(ia);
          degu[u]++;
        }
      }
    }
    for (int v = 1; v <= n2; v++) {
      vector<int> lv = listv[v];
      for (int i = 0; i < int(lv.size()) and degv[v] < deg; i++) {
        int ia = lv[i];
        if (not used[ia]) {
          sol.push_back(ia);
          degv[v]++;
        }
      }
    }
    cout << int(sol.size());
    for (int i = 0; i < int(sol.size()); i++) cout << " " << sol[i];
    cout << endl;
  }
}