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 maxn = 2010;
int maps[maxn * 2][maxn * 2];
int vis[maxn * 2];
int pre[maxn * 2];
int n1, n2, k;
int n;
int deg[maxn * 2];
int s, t;
vector<int> v[maxn * 2];
vector<int> num[maxn];
int bfs(int s, int t) {
  queue<int> q;
  memset(vis, 0, sizeof vis);
  memset(pre, -1, sizeof pre);
  pre[s] = s;
  vis[s] = 1;
  q.push(s);
  while (!q.empty()) {
    int now = q.front();
    q.pop();
    for (int i = 0; i <= n1 + n2 + 1; i++) {
      if (maps[now][i] && !vis[i]) {
        pre[i] = now;
        vis[i] = 1;
        if (i == t) return 1;
        q.push(i);
      }
    }
  }
  return 0;
}
int EK() {
  int i, j;
  int ans = 0;
  while (bfs(s, t)) {
    int minn = (1 << 31) - 1ll;
    for (i = t; i != s; i = pre[i]) {
      minn = min(minn, maps[pre[i]][i]);
    }
    for (i = t; i != s; i = pre[i]) {
      maps[pre[i]][i] -= minn;
      maps[i][pre[i]] += minn;
    }
    ans += minn;
  }
  return ans;
}
vector<int> ans[maxn * 2];
int p[maxn * 2][maxn * 2];
int main() {
  int i, j;
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n1 >> n2 >> k;
  {
    for (i = 0; i < maxn * 2; i++) ans[i].clear(), v[i].clear();
    memset(maps, 0, sizeof maps);
    memset(p, 0, sizeof(p));
    for (i = 1; i <= k; i++) {
      int l, r;
      cin >> l >> r;
      r += n1;
      v[l].push_back(r);
      p[l][r]++;
      num[l].push_back(i);
      deg[l]++;
      deg[r]++;
    }
    n = n1 + n2;
    int minn = 0x3f3f3f3f;
    for (i = 1; i <= n; i++) minn = min(minn, deg[i]);
    int mt = minn;
    s = 0;
    t = n + 1;
    while (minn >= 1) {
      for (i = 1; i <= n1; i++) {
        maps[0][i] = deg[i] - minn;
        maps[i][0] = 0;
      }
      for (i = n1 + 1; i <= n; i++) {
        maps[i][n + 1] = deg[i] - minn;
        maps[n + 1][i] = 0;
      }
      for (i = 1; i <= n1; i++) {
        for (auto it : v[i]) {
          maps[i][it] = p[i][it];
          maps[it][i] = 0;
        }
      }
      int QAQ = EK();
      for (i = 1; i <= n1; i++) {
        for (int j = 0; j < v[i].size(); j++) {
          int it = v[i][j];
          if (maps[i][it]) {
            ans[minn].push_back(num[i][j]), maps[i][it]--;
          }
        }
      }
      minn--;
    }
    cout << 0 << endl;
    for (i = 1; i <= mt; i++) {
      cout << ans[i].size();
      for (auto it : ans[i]) {
        cout << " " << it;
      }
      cout << endl;
    }
  }
  return 0;
}