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;
vector<long long> vis;
void DFS(long long R, vector<vector<pair<long long, long long> > > &G,
         vector<long long> &cap, vector<long long> &capI,
         vector<long long> &ako, vector<long long> &tE) {
  vis.push_back(R);
  if (ako.back() != -1) return;
  for (long long k = 0; k < 5; k++) {
    long long x = rand() % G[R].size();
    auto it = G[R].begin() + x;
    if (ako[it->first] == -1) {
      long long c = (it->second < 0) ? capI[-it->second] : cap[it->second];
      if (c == 0) continue;
      ako[it->first] = R;
      tE[it->first] = it->second;
      DFS(it->first, G, cap, capI, ako, tE);
      if (ako.back() != -1) return;
    }
  }
  for (auto it = G[R].begin(); it != G[R].end(); it++)
    if (ako[it->first] == -1) {
      long long c = (it->second < 0) ? capI[-it->second] : cap[it->second];
      if (c == 0) continue;
      ako[it->first] = R;
      tE[it->first] = it->second;
      DFS(it->first, G, cap, capI, ako, tE);
      if (ako.back() != -1) return;
    }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout << setprecision(25);
  long long n1, n2, m, a, b, c, d, e, f, i, j, k;
  cin >> n1 >> n2 >> m;
  long long n = 2 + n1 + n2;
  vector<vector<pair<long long, long long> > > G(n);
  vector<long long> cap(1, 0);
  vector<long long> capI(1, 0);
  vector<long long> deg1(n1 + 5, 0), deg2(n2 + 5, 0);
  d = 0;
  for (i = 0; i < m; i++) {
    cin >> a >> b;
    d++;
    deg1[a]++;
    deg2[b]++;
    G[a].push_back({n1 + b, d});
    G[n1 + b].push_back({a, -d});
    cap.push_back(1);
    capI.push_back(0);
  }
  long long mi = 3000;
  for (i = 1; i <= n1; i++) mi = min(mi, deg1[i]);
  for (i = 1; i <= n2; i++) mi = min(mi, deg2[i]);
  long long K = mi;
  for (i = 1; i <= n1; i++) {
    d++;
    G[0].push_back({i, d});
    G[i].push_back({0, -d});
    cap.push_back(deg1[i] - K);
    capI.push_back(0);
  }
  for (i = 1; i <= n2; i++) {
    d++;
    G[n1 + i].push_back({n - 1, d});
    G[n - 1].push_back({n1 + i, -d});
    cap.push_back(deg2[i] - K);
    capI.push_back(0);
  }
  vector<long long> ako(n, -1), tE(n);
  long long maxf = 0;
  vector<long long> ans[K + 1];
  for (i = K; i > 0; i--) {
    while (true) {
      ako[0] = 0;
      DFS(0, G, cap, capI, ako, tE);
      bool stop = true;
      if (ako[n - 1] != -1) {
        long long akt = n - 1;
        while (akt != 0) {
          if (tE[akt] > 0)
            cap[tE[akt]]--, capI[tE[akt]]++;
          else
            cap[-tE[akt]]++, capI[-tE[akt]]--;
          akt = ako[akt];
        }
        maxf++;
        stop = false;
      }
      for (auto it = vis.begin(); it != vis.end(); it++) ako[*it] = -1;
      vis.clear();
      if (stop) break;
    }
    for (j = 1; j <= m; j++) {
      if (cap[j]) ans[i].push_back(j);
    }
    for (j = 1; j <= n1; j++) {
      cap[m + j]++;
    }
    for (j = 1; j <= n2; j++) {
      cap[m + n1 + j]++;
    }
  }
  for (i = 0; i <= K; i++) {
    cout << ans[i].size() << " ";
    for (j = 0; j < ans[i].size(); j++) cout << ans[i][j] << " ";
    cout << "\n";
  }
  return 0;
}