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;
inline int read() {
  int x = 0, neg = 1;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-') neg = -1;
    c = getchar();
  }
  while (isdigit(c)) x = x * 10 + c - '0', c = getchar();
  return x * neg;
}
inline void print(int x) {
  if (x < 0) {
    putchar('-');
    print(abs(x));
    return;
  }
  if (x <= 9)
    putchar(x + '0');
  else {
    print(x / 10);
    putchar(x % 10 + '0');
  }
}
inline int qpow(int x, int e, int _MOD) {
  int ans = 1;
  while (e) {
    if (e & 1) ans = ans * x % _MOD;
    x = x * x % _MOD;
    e >>= 1;
  }
  return ans;
}
int n1 = read(), n2 = read(), m = read();
int u[2005], v[2005];
int head[5005];
struct edge {
  int to, nxt, cap;
} e[3000005];
int ecnt = 1;
inline void addedge(int u, int v, int f) {
  e[++ecnt].to = v;
  e[ecnt].cap = f;
  e[ecnt].nxt = head[u];
  head[u] = ecnt;
}
int dep[5005];
inline bool bfs(int s, int t) {
  queue<int> q;
  memset(dep, -1, sizeof(dep));
  q.push(s);
  dep[s] = 0;
  while (!q.empty()) {
    int cur = q.front();
    q.pop();
    for (int i = head[cur]; i; i = e[i].nxt) {
      int to = e[i].to;
      if (dep[to] == -1 && e[i].cap) {
        dep[to] = dep[cur] + 1;
        q.push(to);
      }
    }
  }
  if (dep[t] != -1) return 1;
  return 0;
}
inline int dfs(int x, int t, int f) {
  if (x == t) return f;
  int ret = 0;
  for (int i = head[x]; i; i = e[i].nxt) {
    int y = e[i].to;
    if (dep[y] == dep[x] + 1 && e[i].cap) {
      int w = dfs(y, t, min(f - ret, e[i].cap));
      e[i].cap -= w;
      e[i ^ 1].cap += w;
      ret += w;
      if (ret == f) return f;
    }
  }
  if (ret == 0) dep[x] = -1;
  return ret;
}
inline int Dinic(int s, int t) {
  int tot = 0;
  while (bfs(s, t)) tot += dfs(s, t, 0x3f3f3f3f);
  return tot;
}
int id[2005], deg[4005];
vector<int> ans[2005];
signed main() {
  for (int i = 1; i <= m; i++) {
    u[i] = read();
    v[i] = read();
    v[i] += n1;
    deg[u[i]]++;
    deg[v[i]]++;
  }
  int k = 0x3f3f3f3f;
  for (int i = 1; i <= n1 + n2; i++) k = min(k, deg[i]);
  for (int j = 1; j <= n1; j++) {
    addedge(0, j, deg[j] - k);
    addedge(j, 0, 0);
  }
  for (int j = n1 + 1; j <= n1 + n2; j++) {
    addedge(j, 5000, deg[j] - k);
    addedge(5000, j, 0);
  }
  for (int j = 1; j <= m; j++) {
    addedge(u[j], v[j], 1);
    addedge(v[j], u[j], 0);
    id[j] = ecnt;
  }
  for (int i = k; i >= 0; i--) {
    Dinic(0, 5000);
    for (int j = 1; j <= m; j++) {
      if (e[id[j]].cap == 0) {
        ans[i].push_back(j);
      }
    }
    for (int i = head[0]; i; i = e[i].nxt) e[i].cap++;
    for (int i = head[5000]; i; i = e[i].nxt) e[i ^ 1].cap++;
  }
  for (int i = 0; i <= k; i++) {
    cout << ans[i].size() << " ";
    for (__typeof(ans[i].begin()) it = ans[i].begin(); it != ans[i].end(); it++)
      cout << *it << " ";
    puts("");
  }
  return 0;
}