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 signed int inf = (signed)(~0u >> 1);
template <typename T>
void pfill(T* pst, const T* ped, T val) {
  for (; pst != ped; *(pst++) = val)
    ;
}
typedef class Edge {
 public:
  int ed, nx, r;
  Edge(int ed = 0, int nx = 0, int r = 0) : ed(ed), nx(nx), r(r) {}
} Edge;
typedef class MapManager {
 public:
  int* h;
  vector<Edge> es;
  MapManager() {}
  MapManager(int n) {
    h = new int[(n + 1)];
    pfill(h, h + n + 1, -1);
  }
  ~MapManager() {
    delete[] h;
    es.clear();
  }
  void addEdge(int u, int v, int r) {
    es.push_back(Edge(v, h[u], r));
    h[u] = (signed)es.size() - 1;
  }
  void addArc(int u, int v, int cap) {
    addEdge(u, v, cap);
    addEdge(v, u, 0);
  }
  Edge& operator[](int p) { return es[p]; }
} MapManager;
typedef class Network {
 public:
  int S, T;
  int *cur, *div;
  MapManager g;
  Network() {}
  Network(int S, int T) : S(S), T(T), g(T + 1) {
    cur = new int[(T + 1)];
    div = new int[(T + 1)];
  }
  ~Network() {
    delete[] cur;
    delete[] div;
  }
  bool bfs() {
    static queue<int> que;
    pfill(div, div + T + 1, -1);
    div[S] = 0;
    que.push(S);
    while (!que.empty()) {
      int e = que.front();
      que.pop();
      for (int i = g.h[e], eu; ~i; i = g[i].nx) {
        if (!g[i].r) continue;
        eu = g[i].ed;
        if (!~div[eu]) {
          div[eu] = div[e] + 1;
          que.push(eu);
        }
      }
    }
    return ~div[T];
  }
  int dfs(int p, int minf) {
    if (p == T || !minf) return minf;
    int flow = 0, f;
    for (int &i = cur[p], e; (~i); i = cur[p], i = g[i].nx) {
      e = g[i].ed;
      if (div[e] == div[p] + 1 && (f = dfs(e, min(minf, g[i].r))) > 0) {
        flow += f;
        g[i].r -= f;
        g[i ^ 1].r += f;
        minf -= f;
        if (!minf) {
          break;
        }
      }
    }
    return flow;
  }
  int dinic() {
    int rt = 0;
    while (bfs()) {
      for (int i = 0; i <= T; i++) cur[i] = g.h[i];
      rt += dfs(S, inf);
    }
    return rt;
  }
} Network;
const int N = 2e3 + 5;
int nX, nY, m;
int deg[N << 1];
Network* _network;
vector<int> ans[N];
int main() {
  scanf("%d%d%d", &nX, &nY, &m);
  int n = nX + nY;
  _network = new Network(0, n + 1);
  Network& network = *_network;
  MapManager& g = network.g;
  for (int i = 1, u, v; i <= m; i++) {
    scanf("%d%d", &u, &v);
    g.addArc(u, v + nX, 1);
    deg[u]++, deg[v + nX]++;
  }
  int min_deg = m, sid = g.es.size();
  for (int i = 1; i <= n; i++) {
    min_deg = min(min_deg, deg[i]);
  }
  for (int i = 1; i <= nX; i++) {
    g.addArc(0, i, deg[i] - min_deg);
  }
  for (int i = 1; i <= nY; i++) {
    g.addArc(i + nX, n + 1, deg[i + nX] - min_deg);
  }
  for (int k = min_deg; k; k--) {
    network.dinic();
    for (int i = 0; i < m; i++) {
      if (g[i << 1].r) {
        ans[k].push_back(i + 1);
      }
    }
    for (int i = 0; i < n; i++) {
      g[sid + (i << 1)].r++;
    }
  }
  for (int k = 0; k <= min_deg; k++) {
    printf("%d", (signed)ans[k].size());
    for (int i = 0; i < (signed)ans[k].size(); i++) {
      printf(" %d", ans[k][i]);
    }
    putchar('\n');
  }
  return 0;
}