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;
template <class T, class U>
void ckmin(T &a, U b) {
  if (a > b) a = b;
}
template <class T, class U>
void ckmax(T &a, U b) {
  if (a < b) a = b;
}
int N1, N, M, D;
int deg[4013];
vector<int> ans[4013];
int V, E = 2, S, T;
int to[100013], link[100013], cap[100013], id[100013];
int head[4013], dist[4013];
bitset<4013> seen;
void addedge(int u, int v, int c, int i = 0) {
  to[E] = v;
  link[E] = head[u];
  head[u] = E;
  cap[E] = c;
  id[E] = i;
  E++;
  to[E] = u;
  link[E] = head[v];
  head[v] = E;
  cap[E] = 0;
  id[E] = 0;
  E++;
}
bool bfs() {
  for (auto i = (0); i < (V); i++) {
    dist[i] = 1000000007;
    seen[i] = false;
  }
  dist[S] = 0;
  queue<int> q;
  q.push(S);
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int e = head[u]; e; e = link[e]) {
      int v = to[e];
      if (cap[e] == 0) continue;
      if (dist[v] > dist[u] + 1) {
        dist[v] = dist[u] + 1;
        q.push(v);
      }
    }
  }
  return (dist[T] != 1000000007);
}
int aug(int u, int f) {
  if (u == T) {
    return f;
  }
  seen[u] = true;
  int cur = 0;
  for (int e = head[u]; e; e = link[e]) {
    int v = to[e];
    if (dist[v] != dist[u] + 1) continue;
    if (cap[e] == 0) continue;
    if (seen[v]) continue;
    int gain = aug(v, min(cap[e], f));
    cap[e] -= gain;
    cap[e ^ 1] += gain;
    cur += gain;
    f -= gain;
  }
  return cur;
}
int maxflow() {
  int res = 0;
  while (true) {
    if (!bfs()) return res;
    res += aug(S, 1000000007);
  }
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> N1 >> N >> M;
  N += N1;
  for (auto i = (0); i < (M); i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    v += N1;
    addedge(u, v, 1, i + 1);
    deg[u]++;
    deg[v]++;
  }
  D = 1000000007;
  for (auto i = (0); i < (N); i++) {
    ckmin(D, deg[i]);
  }
  V = N + 2;
  S = N;
  T = N + 1;
  for (auto i = (0); i < (N1); i++) {
    addedge(S, i, deg[i] - D);
  }
  for (auto i = (N1); i < (N); i++) {
    addedge(i, T, deg[i] - D);
  }
  for (auto i = (D + 1) - 1; i >= (0); i--) {
    maxflow();
    for (auto u = (0); u < (N1); u++) {
      for (int e = head[u]; e; e = link[e]) {
        int v = to[e];
        if (v == S || cap[e] == 0) continue;
        ans[i].push_back(id[e]);
      }
    }
    for (int e = head[S]; e; e = link[e]) {
      cap[e]++;
    }
    for (int e = head[T]; e; e = link[e]) {
      cap[e ^ 1]++;
    }
  }
  for (auto i = (0); i < (D + 1); i++) {
    sort((ans[i]).begin(), (ans[i]).end());
    cout << ((int)((ans[i]).size()));
    for (int x : ans[i]) {
      cout << ' ' << x;
    }
    cout << '\n';
  }
  return 0;
}