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>
const int mod = 1000000007;
const int inf = 1000000009;
const long long INF = 1000000000000000009;
const long long big = 1000000000000000;
const long double eps = 0.000000000000000000001;
using namespace std;
class DINIC {
 public:
  queue<int> Q;
  int n, source, sink;
  vector<int> cur, dis;
  vector<vector<int> > cap;
  vector<vector<int> > nei;
  bool bfs() {
    dis = vector<int>(n + 1, -1);
    dis[source] = 0;
    Q.push(source);
    while (!Q.empty()) {
      int u = Q.front();
      Q.pop();
      for (int v : nei[u])
        if (!~dis[v] && cap[u][v]) {
          dis[v] = dis[u] + 1;
          Q.push(v);
        }
    }
    return ~dis[sink];
  }
  int dfs(int u, int mincap) {
    if (!mincap || u == sink) return mincap;
    int res = 0;
    for (int i = cur[u]; i < nei[u].size(); i++) {
      if (!mincap)
        break;
      else
        cur[u] = i;
      int v = nei[u][i];
      if (dis[v] == dis[u] + 1) {
        int f = dfs(v, min(mincap, cap[u][v]));
        mincap -= f;
        res += f;
        cap[u][v] -= f;
        cap[v][u] += f;
      }
    }
    return res;
  }

 public:
  DINIC(int n, int source, int sink)
      : n(n),
        source(source),
        sink(sink),
        cap(n + 1, vector<int>(n + 1, 0)),
        nei(n + 1) {}
  int flow() {
    int res = 0;
    while (bfs()) {
      cur = vector<int>(n + 1, 0);
      res += dfs(source, 1000000001);
    }
    return res;
  }
  void addEdge(int fr, int to, int cap1, int cap2 = 0) {
    nei[fr].push_back(to);
    nei[to].push_back(fr);
    cap[fr][to] += cap1;
    cap[to][fr] += cap2;
  }
};
int A[2005], B[2005];
map<pair<int, int>, vector<int> > M;
map<pair<int, int>, int> Dod;
vector<int> W[2005];
vector<pair<pair<int, int>, int> > K;
int main() {
  ios::sync_with_stdio(false);
  cin.tie();
  cout.tie();
  int x, y, m;
  cin >> x >> y >> m;
  DINIC D(x + y + 2, 0, x + y + 1);
  for (int i = 1; i <= m; i++) {
    int a, b;
    cin >> a >> b;
    A[a]++, B[b]++;
    D.addEdge(a, x + b, 1);
    M[make_pair(a, b)].push_back(i);
    K.push_back(make_pair(make_pair(a, b), i));
  }
  int s = inf;
  for (int i = 1; i <= x; i++) {
    s = min(s, A[i]);
  }
  for (int i = 1; i <= y; i++) {
    s = min(s, B[i]);
  }
  for (int i = 1; i <= x; i++) {
    D.addEdge(0, i, A[i] - s);
  }
  for (int i = 1; i <= y; i++) {
    D.addEdge(x + i, x + y + 1, B[i] - s);
  }
  for (int i = s; i >= 0; i--) {
    D.flow();
    for (auto v : K) {
      if (D.cap[v.first.first][v.first.second + x] - Dod[v.first] >= 1) {
        Dod[v.first]++;
        W[i].push_back(M[v.first].back());
        M[v.first].pop_back();
      }
    }
    for (auto v : K) {
      Dod[v.first] = 0;
      M[v.first].clear();
    }
    for (auto v : K) M[v.first].push_back(v.second);
    for (int j = 1; j <= x; j++) D.cap[0][j]++;
    for (int j = 1; j <= y; j++) D.cap[j + x][x + y + 1]++;
  }
  for (int i = 0; i <= s; i++) {
    cout << W[i].size() << " ";
    for (auto v : W[i]) cout << v << " ";
    cout << "\n";
  }
  return 0;
}