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;
const int N = 5000 + 10;
const int INF = 1e9 + 7;
struct Edge {
  int from, to, cap, flow, id;
};
bool visit[N];
struct Dinic {
  int n, m, s, t;
  vector<Edge> edges;
  vector<int> f[N];
  bool vis[N];
  int d[N];
  int cur[N];
  void init(int n) {
    this->n = n;
    edges.clear();
    for (int i = 0; i < N; i++) f[i].clear();
    memset(d, 0, sizeof(d));
    memset(cur, 0, sizeof(cur));
    memset(visit, 0, sizeof(visit));
  }
  void AddEdge(int from, int to, int cap, int id) {
    edges.push_back((Edge){from, to, cap, 0, id});
    edges.push_back((Edge){to, from, 0, 0, id});
    m = edges.size();
    f[from].push_back(m - 2);
    f[to].push_back(m - 1);
  }
  bool BFS() {
    memset(vis, 0, sizeof(vis));
    queue<int> q;
    q.push(s);
    d[s] = 0;
    vis[s] = 1;
    while (!q.empty()) {
      int x = q.front();
      q.pop();
      for (int i = 0; i < f[x].size(); i++) {
        Edge& e = edges[f[x][i]];
        if (!vis[e.to] && e.flow < e.cap) {
          vis[e.to] = 1;
          d[e.to] = d[x] + 1;
          q.push(e.to);
        }
      }
    }
    return vis[t];
  }
  int DFS(int x, int a) {
    if (x == t || a == 0) return a;
    int flow = 0, r;
    for (int& i = cur[x]; i < f[x].size(); i++) {
      Edge& e = edges[f[x][i]];
      if (d[x] + 1 == d[e.to] && (r = DFS(e.to, min(a, e.cap - e.flow))) > 0) {
        e.flow += r;
        edges[f[x][i] ^ 1].flow -= r;
        flow += r;
        a -= r;
        if (a == 0) break;
      }
    }
    return flow;
  }
  int MaxFlow(int s, int t) {
    this->s = s;
    this->t = t;
    int flow = 0;
    while (BFS()) {
      memset(cur, 0, sizeof(cur));
      flow += DFS(s, INF);
    }
    for (int i = 0; i < edges.size(); i++) {
      if (edges[i].flow) visit[edges[i].id] = 1;
    }
    return flow;
  }
} G;
int n1, n2, m, deg[N];
vector<pair<int, int> > v[N];
void build_gragh(int k) {
  int S = n1 + n2 + 1, T = n1 + n2 + 2;
  G.init(T + 2);
  for (int i = 1; i <= n1; i++) {
    G.AddEdge(S, i, deg[i] - k, 0);
  }
  for (int i = 1; i <= n2; i++) {
    G.AddEdge(i + n1, T, deg[i + n1] - k, 0);
  }
  for (int i = 1; i <= n1; i++) {
    for (int j = 0; j < v[i].size(); j++) {
      G.AddEdge(i, v[i][j].first + n1, 1, v[i][j].second);
    }
  }
  int ret = G.MaxFlow(S, T);
  printf("%d ", m - ret);
  for (int i = 1; i <= m; i++) {
    if (visit[i] == 0) printf("%d ", i);
  }
  printf("\n");
}
int main() {
  scanf("%d%d%d", &n1, &n2, &m);
  for (int i = 1; i <= m; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    v[x].push_back(make_pair(y, i));
    deg[x]++, deg[n1 + y]++;
  }
  printf("0\n");
  int mnDegree = *min_element(deg + 1, deg + 1 + n1 + n2);
  for (int i = 1; i <= mnDegree; i++) {
    build_gragh(i);
  }
}