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 INF = 1e9;
const int MAXN = 150005;
const int MAXM = 1900000;
int N, edges;
int last[MAXN], preve[MAXM], head[MAXM];
int Cap[MAXM], Flow[MAXM];
int dist[MAXN];
int nextEdge[MAXN];
int edgeno[MAXN];
queue<int> Q;
void init() {
  edges = 0;
  memset(last, -1, sizeof last);
}
inline void add_edge(int u, int v, int cap, int flow = 0) {
  head[edges] = v;
  preve[edges] = last[u];
  Cap[edges] = cap;
  Flow[edges] = flow;
  last[u] = edges++;
  head[edges] = u;
  preve[edges] = last[v];
  Cap[edges] = 0;
  Flow[edges] = 0;
  last[v] = edges++;
}
inline bool dinicBfs(int S, int E, int N) {
  int from = S, to, cap, flow;
  memset(dist, 0, sizeof(int) * N);
  dist[from] = 1;
  while (!Q.empty()) Q.pop();
  Q.push(from);
  while (!Q.empty()) {
    from = Q.front();
    Q.pop();
    for (int e = last[from]; e >= 0; e = preve[e]) {
      to = head[e];
      cap = Cap[e];
      flow = Flow[e];
      if (!dist[to] && cap > flow) {
        dist[to] = dist[from] + 1;
        Q.push(to);
        if (to == E) return true;
      }
    }
  }
  return (dist[E] != 0);
}
inline int dfs(int from, int minEdge, int E) {
  if (!minEdge) return 0;
  if (from == E) return minEdge;
  int to, e, cap, flow, ret;
  for (; nextEdge[from] >= 0; nextEdge[from] = preve[e]) {
    e = nextEdge[from];
    to = head[e];
    cap = Cap[e];
    flow = Flow[e];
    if (dist[to] != dist[from] + 1) continue;
    ret = dfs(to, min(minEdge, cap - flow), E);
    if (ret) {
      Flow[e] += ret;
      Flow[e ^ 1] -= ret;
      return ret;
    }
  }
  return 0;
}
int dinicUpdate(int S, int E) {
  int flow = 0;
  while (int minEdge = dfs(S, INF, E)) {
    if (minEdge == 0) break;
    flow += minEdge;
  }
  return flow;
}
int maxFlow(int S, int E, int N) {
  int totFlow = 0;
  while (dinicBfs(S, E, N)) {
    for (int i = 0; i <= N; i++) nextEdge[i] = last[i];
    totFlow += dinicUpdate(S, E);
  }
  return totFlow;
}
int diss[MAXN], my[MAXN], deg[MAXN];
vector<int> ou[2005];
int main() {
  int i, j, k, l, m, n1, ma = INT_MAX, n2;
  scanf("%d%d%d", &n1, &n2, &m);
  init();
  int sou = 0, sink = n1 + n2 + 1;
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &l, &k);
    my[i] = edges;
    k += n1;
    add_edge(l, k, 1, 0);
    deg[l]++;
    deg[k]++;
  }
  for (int i = 1; i <= n1 + n2; i++) {
    ma = min(ma, deg[i]);
  }
  for (int i = 1; i <= n1; i++) {
    diss[i] = edges;
    add_edge(sou, i, deg[i] - ma);
  }
  for (int i = n1 + 1; i <= n1 + n2; i++) {
    diss[i] = edges;
    add_edge(i, sink, deg[i] - ma);
  }
  for (int i = ma; i >= 0; i--) {
    maxFlow(sou, sink, sink + 2);
    int cnt = 0;
    for (int j = 1; j <= m; j++) {
      int e = my[j];
      if (Flow[e]) continue;
      ou[i].push_back(j);
    }
    for (int j = 1; j <= n1 + n2; j++) {
      int e = diss[j];
      Cap[e]++;
    }
  }
  for (int i = 0; i <= ma; i++) {
    printf("%d", ou[i].size());
    for (int j = 0; j < ou[i].size(); j++) {
      printf(" %d", ou[i][j]);
    }
    printf("\n");
  }
}