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;
int n1, n2, m, DEG[4040];
vector<int> res[4040];
struct edge {
  int u, v, cap, flow;
};
struct Graph {
  int n;
  vector<vector<int> > g;
  vector<edge> e;
  vector<int> d, ptr;
  Graph() {}
  Graph(int n) : n(n), g(n + 1), d(n + 1), ptr(n + 1) {}
  void addEdge(int u, int v, int cap) {
    edge ee = {u, v, cap, 0};
    g[u].push_back(e.size());
    e.push_back(ee);
    ee = {v, u, 0, 0};
    g[v].push_back(e.size());
    e.push_back(ee);
  }
  void MaxFlow(int s, int t) {
    while (bfs(s, t)) {
      while (dfs(s, t))
        ;
    }
  }
  void IncreaseCap(int s, int t) {
    for (int id : g[s]) e[id].cap++;
    for (int id : g[t]) e[id ^ 1].cap++;
  }

 private:
  bool bfs(int s, int t) {
    for (int i = (0); i <= (n); ++i) d[i] = -1, ptr[i] = 0;
    d[s] = 0;
    queue<int> q;
    q.push(s);
    while (!q.empty()) {
      int u = q.front();
      q.pop();
      for (int id : g[u]) {
        if (e[id].flow < e[id].cap) {
          int v = e[id].v;
          if (d[v] == -1) {
            d[v] = d[u] + 1;
            q.push(v);
          }
        }
      }
    }
    return d[t] != -1;
  }
  bool dfs(int u, int t) {
    if (u == t) return 1;
    for (; ptr[u] < (int)g[u].size(); ++ptr[u]) {
      int id = g[u][ptr[u]];
      if (e[id].flow < e[id].cap) {
        int v = e[id].v;
        if (d[v] == d[u] + 1 && dfs(v, t)) {
          e[id].flow++;
          e[id ^ 1].flow--;
          return 1;
        }
      }
    }
    return 0;
  }
};
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n1 >> n2 >> m;
  Graph G(n1 + n2 + 2);
  for (int i = (1); i <= (m); ++i) {
    int u, v;
    cin >> u >> v;
    v += n1;
    DEG[u]++;
    DEG[v]++;
    G.addEdge(u, v, 1);
  }
  int k = DEG[1];
  for (int i = (2); i <= (n1 + n2); ++i) k = min(k, DEG[i]);
  for (int i = (1); i <= (n1); ++i) G.addEdge(0, i, DEG[i] - k);
  for (int i = (1); i <= (n2); ++i)
    G.addEdge(i + n1, n1 + n2 + 1, DEG[i + n1] - k);
  for (int i = (k); i >= (0); --i) {
    G.MaxFlow(0, n1 + n2 + 1);
    for (int j = 0; j < (m); ++j)
      if (G.e[j * 2].flow != G.e[j * 2].cap) res[i].push_back(j + 1);
    G.IncreaseCap(0, n1 + n2 + 1);
  }
  for (int i = (0); i <= (k); ++i) {
    cout << res[i].size() << ' ';
    for (int id : res[i]) cout << id << ' ';
    cout << '\n';
  }
}