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;
struct edge {
  int to, cap, rev, id;
  edge(int a = 0, int b = 0, int c = 0, int d = 0) {
    to = a, cap = b, rev = c, id = d;
  }
};
bool visit[4005];
int indg[4005], level[4005], iter[4005], n1, n2, m, s, t, store[4005];
vector<edge> graph[4005];
vector<edge> standard[4005];
void add_e(int from, int to, int cap, int id) {
  graph[from].push_back(edge(to, cap, graph[to].size(), id));
  graph[to].push_back(edge(from, 0, graph[from].size() - 1, id));
}
void bfs(int s) {
  memset(level, -1, sizeof(level));
  queue<int> que;
  level[s] = 0;
  que.push(s);
  while (que.size()) {
    int v = que.front();
    que.pop();
    for (int i = 0; i < graph[v].size(); ++i) {
      edge& e = graph[v][i];
      if (e.cap > 0 && level[e.to] < 0) {
        level[e.to] = level[v] + 1;
        que.push(e.to);
      }
    }
  }
}
int dfs(int v, int t, int f) {
  if (v == t) return f;
  for (int& i = iter[v]; i < graph[v].size(); ++i) {
    edge& e = graph[v][i];
    if (e.cap > 0 && level[v] < level[e.to]) {
      int d = dfs(e.to, t, min(f, e.cap));
      if (d > 0) {
        e.cap -= d;
        graph[e.to][e.rev].cap += d;
        return d;
      }
    }
  }
  return 0;
}
int max_flow(int s, int t) {
  int flow = 0;
  while (true) {
    bfs(s);
    if (level[t] < 0) return flow;
    memset(iter, 0, sizeof(iter));
    int f;
    while ((f = dfs(s, t, 0x3f3f3f3f)) > 0) {
      flow += f;
    }
  }
}
int main() {
  scanf("%d%d%d", &n1, &n2, &m);
  s = 0, t = n1 + n2 + 1;
  for (int i = 0; i < m; ++i) {
    int u, v;
    scanf("%d%d", &u, &v);
    v += n1;
    ++indg[u], ++indg[v];
    standard[u].push_back(edge(v, 1, standard[v].size(), i + 1));
    standard[v].push_back(edge(u, 0, standard[u].size() - 1, i + 1));
  }
  int mdg = 4005;
  for (int i = 1; i <= n1 + n2; ++i) mdg = min(mdg, indg[i]);
  printf("0\n");
  for (int k = 1; k <= mdg; ++k) {
    for (int v = 0; v < 4005; ++v) graph[v].clear();
    for (int i = 1; i <= n1 + n2; ++i) {
      for (int j = 0; j < standard[i].size(); ++j)
        graph[i].push_back(standard[i][j]);
    }
    for (int i = 1; i <= n1; ++i) add_e(s, i, indg[i] - k, -1);
    for (int i = n1 + 1; i <= n1 + n2; ++i) add_e(i, t, indg[i] - k, -1);
    max_flow(s, t);
    memset(visit, false, sizeof(visit));
    int cnt = 0;
    for (int i = n1 + 1; i <= n1 + n2; ++i) {
      for (int j = 0; j < graph[i].size(); ++j) {
        edge& e = graph[i][j];
        if (e.cap && e.to != t) {
          visit[e.id] = true;
          ++cnt;
        }
      }
    }
    printf("%d", m - cnt);
    for (int i = 1; i <= m; ++i) {
      if (!visit[i]) printf(" %d", i);
    }
    printf("\n");
  }
  return 0;
}