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 MAX = 200010;
const int MOD = 1000000007;
const int INF = 1e8;
const long long LLINF = 0x3f3f3f3f3f3f3f3f;
const long double EPS = 1e-7;
const int N = 4010;
struct Dinic {
  struct Edge {
    int from, to;
    long long flow, cap;
  };
  vector<Edge> edge;
  vector<int> g[N];
  int ne = 0;
  int lvl[N], vis[N], pass;
  int qu[N], px[N], qt;
  long long run(int s, int sink, long long minE) {
    if (s == sink) return minE;
    long long ans = 0;
    for (; px[s] < (int)g[s].size(); px[s]++) {
      int e = g[s][px[s]];
      auto &v = edge[e], &rev = edge[e ^ 1];
      if (lvl[v.to] != lvl[s] + 1 || v.flow >= v.cap) continue;
      long long tmp = run(v.to, sink, min(minE, v.cap - v.flow));
      v.flow += tmp, rev.flow -= tmp;
      ans += tmp, minE -= tmp;
      if (minE == 0) break;
    }
    return ans;
  }
  bool bfs(int source, int sink) {
    qt = 0;
    qu[qt++] = source;
    lvl[source] = 1;
    vis[source] = ++pass;
    for (int i = 0; i < qt; i++) {
      int u = qu[i];
      px[u] = 0;
      if (u == sink) return true;
      for (auto& ed : g[u]) {
        auto v = edge[ed];
        if (v.flow >= v.cap || vis[v.to] == pass) continue;
        vis[v.to] = pass;
        lvl[v.to] = lvl[u] + 1;
        qu[qt++] = v.to;
      }
    }
    return false;
  }
  long long flow(int source, int sink) {
    reset_flow();
    long long ans = 0;
    while (bfs(source, sink)) {
      ans += run(source, sink, LLINF);
    }
    return ans;
  }
  void addEdge(int u, int v, long long c, long long rc) {
    Edge e = {u, v, 0, c};
    edge.push_back(e);
    g[u].push_back(ne++);
    e = {v, u, 0, rc};
    edge.push_back(e);
    g[v].push_back(ne++);
  }
  void reset_flow() {
    for (int i = 0; i < ne; i++) edge[i].flow = 0;
    memset(lvl, 0, sizeof(lvl));
    memset(vis, 0, sizeof(vis));
    memset(qu, 0, sizeof(qu));
    memset(px, 0, sizeof(px));
    qt = 0;
    pass = 0;
  }
};
int grau1[2010], grau2[2010];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int n1, n2, m, u, v;
  int sink = 4006, source = 4005;
  cin >> n1 >> n2 >> m;
  Dinic d;
  vector<pair<int, int> > vet;
  for (int i = 0; i < m; i++) {
    cin >> u >> v;
    u--;
    v--;
    vet.push_back({u, v});
    grau1[u]++;
    grau2[v]++;
  }
  int val = INF;
  for (int i = 0; i < n1; i++) val = min(val, grau1[i]);
  for (int i = 0; i < n2; i++) val = min(val, grau2[i]);
  for (int i = 0; i < n1; i++) d.addEdge(sink, i, grau1[i] - val, 0);
  for (int i = 0; i < n2; i++) d.addEdge(i + n1, source, grau2[i] - val, 0);
  for (int i = 0; i < m; i++) d.addEdge(vet[i].first, vet[i].second + n1, 1, 0);
  vector<vector<int> > ans(val, vector<int>());
  d.flow(sink, source);
  for (int i = 0; i < m; i++) {
    int ind = n1 + n2 + i;
    if (d.edge[2 * ind].flow == 0) ans[0].push_back(i + 1);
  }
  for (int i = 1; i < val; i++) {
    for (int j = 0; j < n1 + n2; j++) d.edge[2 * j].cap++;
    d.flow(sink, source);
    for (int j = 0; j < m; j++) {
      int ind = n1 + n2 + j;
      if (d.edge[2 * ind].flow == 0) ans[i].push_back(j + 1);
    }
  }
  cout << 0 << '\n';
  for (int i = val - 1; i >= 0; i--) {
    cout << ans[i].size();
    for (auto a : ans[i]) cout << " " << a;
    cout << '\n';
  }
  return 0;
}