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;
using INT = long long;
int V, E, src, tar;
int head[202020], work[202020], dis[202020];
int to[400000], cap[400000], nxt[400000];
int q[1000111], qf, qb;
int id[202020];
void init(int n, int s, int t) {
  V = n;
  E = 0;
  src = s;
  tar = t;
  memset(head, -1, sizeof(int) * V);
}
void add_edge(int u, int v, int c, int ID = 0) {
  to[E] = v;
  cap[E] = c;
  id[E] = ID;
  nxt[E] = head[u];
  head[u] = E++;
  to[E] = u;
  cap[E] = 0;
  id[E] = ID;
  nxt[E] = head[v];
  head[v] = E++;
}
bool bfs() {
  memset(dis, -1, sizeof(dis));
  qf = qb = 0;
  q[qb++] = src;
  dis[src] = 0;
  while (qf < qb && dis[tar] == -1) {
    int u = q[qf++];
    for (int i = head[u]; i >= 0; i = nxt[i]) {
      int v = to[i];
      if (dis[v] == -1 && cap[i] > 0) {
        dis[v] = dis[u] + 1;
        q[qb++] = v;
      }
    }
  }
  return dis[tar] >= 0;
}
int dfs(int u, int &bot) {
  int v, bot1, delta;
  if (u == tar) return bot;
  for (int &i = work[u]; i >= 0; i = nxt[i]) {
    int v = to[i];
    if (dis[v] != dis[u] + 1 || cap[i] == 0) continue;
    bot1 = min(bot, cap[i]);
    if (delta = dfs(v, bot1)) {
      cap[i] -= delta;
      cap[i ^ 1] += delta;
      bot = bot1;
      return delta;
    }
  }
  return 0;
}
int dinic() {
  int ans = 0, delta, bot;
  while (bfs()) {
    memcpy(work, head, sizeof(int) * V);
    delta = 1000000000;
    while (delta = dfs(src, bot = 1000000000)) ans += delta;
  }
  return ans;
}
int deg[202020];
vector<int> ans[202020];
int flag[202020];
int main() {
  int n1, n2, m;
  cin >> n1 >> n2 >> m;
  int src = n1 + n2 + 1, tar = src + 1;
  init(tar + 10, src, tar);
  int mn = m + 1;
  for (int i = 1; i <= m; i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    add_edge(u, v + n1, 1, i);
    deg[u]++;
    deg[v + n1]++;
  }
  for (int i = 1; i <= n1 + n2; i++) {
    mn = min(mn, deg[i]);
  }
  for (int i = 1; i <= n1; i++) {
    add_edge(src, i, deg[i] - mn - 1);
  }
  for (int i = 1; i <= n2; i++) {
    add_edge(i + n1, tar, deg[i + n1] - mn - 1);
  }
  for (int ii = mn; ii >= 0; ii--) {
    for (int e = head[src]; ~e; e = nxt[e]) {
      cap[e]++;
    }
    for (int e = head[tar]; ~e; e = nxt[e]) {
      cap[e ^ 1]++;
    }
    dinic();
    for (int i = 1; i <= m; i++) flag[i] = 1;
    for (int i = 1; i <= n1; i++) {
      for (int e = head[i]; ~e; e = nxt[e])
        if (to[e] != src and !cap[e]) {
          flag[id[e]] = 0;
        }
    }
    for (int i = 1; i <= m; i++)
      if (flag[i]) {
        ans[ii].push_back(i);
      }
  }
  for (int ii = 0; ii <= mn; ii++) {
    cout << ans[ii].size() << ' ';
    for (auto u : ans[ii]) printf("%d ", u);
    puts("");
  }
}