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;
vector<pair<int, int> > adjList[20000];
int ned, prv[20000], first[20000];
int cap[20000], to[20000], nxt[20000], dist[20000], val[20000];
void init() {
  memset(first, -1, sizeof first);
  ned = 0;
}
void add(int u, int v, int f, int l) {
  to[ned] = v, cap[ned] = f;
  nxt[ned] = first[u];
  val[ned] = l;
  first[u] = ned++;
  to[ned] = u, cap[ned] = 0;
  nxt[ned] = first[v];
  val[ned] = l;
  first[v] = ned++;
}
int augment(int v, int minEdge, int s) {
  int e = prv[v];
  if (e == -1) return minEdge;
  int f = augment(to[e ^ 1], min(minEdge, cap[e]), s);
  cap[e] -= f;
  cap[e ^ 1] += f;
  return f;
}
bool bfs(int s, int t) {
  int u, v;
  memset(&dist, -1, sizeof dist);
  dist[s] = 0;
  queue<int> q;
  q.push(s);
  memset(&prv, -1, sizeof prv);
  while (!q.empty()) {
    u = q.front();
    q.pop();
    if (u == t) break;
    for (int e = first[u]; e != -1; e = nxt[e]) {
      v = to[e];
      if (dist[v] < 0 && cap[e] > 0) {
        dist[v] = dist[u] + 1;
        q.push(v);
        prv[v] = e;
      }
    }
  }
  return dist[t] >= 0;
}
int edmondskarp(int s, int t) {
  int result = 0;
  while (bfs(s, t)) {
    result += augment(t, 1000000007, s);
  }
  return result;
}
int edges[20000] = {}, lim[20000] = {};
vector<int> ans[20000];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int u, v;
  cin >> N1 >> N2 >> M;
  for (int i = 0; i < M; ++i) {
    cin >> u >> v;
    v += N1;
    edges[u]++, edges[v]++;
    adjList[u].push_back(pair<int, int>(v, i + 1));
    adjList[v].push_back(pair<int, int>(u, i + 1));
  }
  int k = 1000000007;
  int s = 0, t = N1 + N2 + 1;
  for (int i = 1; i < t; ++i) k = min(k, edges[i]);
  init();
  for (int i = 1; i < N1 + 1; ++i) {
    add(s, i, edges[i] - k, -1);
    lim[i] = ned - 2;
    for (pair<int, int> v : adjList[i]) add(i, v.first, 1, v.second);
  }
  for (int i = N1 + 1; i < t; ++i) {
    add(i, t, edges[i] - k, -1);
    lim[i] = ned - 2;
  }
  for (int j = 0; j < k + 1; ++j) {
    edmondskarp(s, t);
    for (int i = 1; i < N1 + 1; ++i) {
      for (int e = first[i]; e != -1; e = nxt[e]) {
        if (to[e] > N1 && to[e] <= N1 + N2 && cap[e]) {
          ans[k - j].push_back(val[e]);
        }
      }
    }
    for (int i = 1; i < t; ++i) cap[lim[i]]++;
  }
  for (int i = 0; i < k + 1; ++i) {
    cout << ans[i].size();
    for (int u : ans[i]) cout << ' ' << u;
    cout << '\n';
  }
}