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>
#pragma GCC optimize(2)
using namespace std;
const int INF = 0x3f3f3f3f;
const int GRAPH_SIZE = 4000 + 20;
int pin[GRAPH_SIZE], dep[GRAPH_SIZE], s = 0, t = GRAPH_SIZE - 1;
struct EDGE {
  int u, v, c, id;
};
vector<EDGE> e;
vector<int> each[GRAPH_SIZE];
class MAX_FLOW {
  bool bfs() {
    queue<int> Q;
    Q.push(s);
    while (!Q.empty()) {
      int now = Q.front();
      Q.pop();
      for (auto it : each[now]) {
        int next = e[it].v;
        if (e[it].c)
          if (dep[next] > dep[now] + 1) {
            dep[next] = dep[now] + 1;
            Q.push(next);
          }
      }
    }
    return dep[t] != INF;
  }
  int dfs(int now, int flow) {
    if (now == t) {
      return flow;
    }
    for (int& i = pin[now]; i < each[now].size(); i++) {
      int it = each[now][i];
      if (e[it].c && dep[e[it].v] == dep[now] + 1) {
        int tmp;
        if (tmp = dfs(e[it].v, min(flow, e[it].c))) {
          e[it].c -= tmp;
          e[it ^ 1].c += tmp;
          return tmp;
        }
      }
    }
    return 0;
  }

 public:
  int Dinic() {
    int max_flow = 0;
    for (int i = 0; i < GRAPH_SIZE; ++i) {
      dep[i] = INF;
    }
    dep[s] = 0;
    while (bfs()) {
      for (int i = 0; i < GRAPH_SIZE; ++i) {
        pin[i] = 0;
      }
      int tmp;
      while (tmp = dfs(s, INF)) {
        max_flow += tmp;
      }
      for (int i = 0; i < GRAPH_SIZE; ++i) {
        dep[i] = INF;
      }
      dep[s] = 0;
    }
    return max_flow;
  }

 public:
  void make_edge(int U, int V, int C, int ID) {
    EDGE tmp;
    tmp.u = U;
    tmp.v = V;
    tmp.c = C;
    tmp.id = ID;
    e.push_back(tmp);
    each[U].push_back(e.size() - 1);
    swap(tmp.u, tmp.v);
    tmp.c = 0;
    e.push_back(tmp);
    each[V].push_back(e.size() - 1);
  }
  void init() {
    e.clear();
    for (int i = 0; i < GRAPH_SIZE; ++i) {
      each[i].clear();
    }
  }
} mf;
int n1, n2, m;
int deg[GRAPH_SIZE];
int main() {
  ios::sync_with_stdio(false);
  cin >> n1 >> n2 >> m;
  int MK = 0;
  for (int i = 1; i <= m; ++i) {
    int u, v;
    cin >> u >> v;
    v += n1;
    deg[u]++;
    deg[v]++;
    mf.make_edge(u, v, 1, i);
  }
  int k = INF;
  for (int i = 1; i <= n1 + n2; ++i) {
    k = min(k, deg[i]);
  }
  vector<vector<int> > rest;
  for (int i = 1; i <= n1; ++i) mf.make_edge(s, i, deg[i] - k, 0);
  for (int i = n1 + 1; i <= n1 + n2; ++i) mf.make_edge(i, t, deg[i] - k, 0);
  for (int ZZ = 0; ZZ <= k; ++ZZ) {
    rest.push_back(vector<int>(0));
    mf.Dinic();
    for (int i = 1; i <= n1; ++i)
      for (auto it : each[i])
        if (e[it].v > n1)
          if (e[it].c == 1) {
            rest[ZZ].push_back(e[it].id);
          }
    for (int i = 1; i <= n1; ++i) mf.make_edge(s, i, 1, 0);
    for (int i = n1 + 1; i <= n1 + n2; ++i) mf.make_edge(i, t, 1, 0);
  }
  reverse(rest.begin(), rest.end());
  for (auto it : rest) {
    cout << it.size() << ' ';
    for (auto itt : it) cout << itt << ' ';
    cout << endl;
  }
  return 0;
}