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 Maxflow {
  struct edge {
    int from, to;
    long long flow, capacity;
    int id;
  };
  int s, t;
  vector<edge> edg;
  vector<int> g[4111];
  int dist[4111], visited[4111];
  int cur[4111];
  void init() {
    edg.clear();
    int i;
    for (i = 0; i < 4111; i++) {
      g[i].clear();
    }
  }
  void addedge(int from, int to, long long capacity, int id) {
    edge e1 = edge{from, to, 0ll, capacity, id};
    edge e2 = edge{to, from, 0ll, 0ll, -1};
    edg.push_back(e1), edg.push_back(e2);
    g[from].push_back((int)edg.size() - 2);
    g[to].push_back((int)edg.size() - 1);
  }
  bool bfs() {
    memset(visited, 0, sizeof(visited));
    memset(dist, 0, sizeof(dist));
    queue<int> q;
    q.push(s);
    visited[s] = 1;
    dist[s] = 0;
    while (!q.empty()) {
      int v = q.front();
      q.pop();
      for (int i = 0; i < (int)g[v].size(); i++) {
        edge &e = edg[g[v][i]];
        int nxt = e.to;
        if (!visited[nxt] && e.capacity > e.flow) {
          dist[nxt] = dist[v] + 1;
          q.push(nxt);
          visited[nxt] = 1;
        }
      }
    }
    return visited[t];
  }
  long long dfs(int x, long long cp) {
    if (x == t || cp == 0) {
      return cp;
    }
    long long flow = 0, newflow;
    for (int &y = cur[x]; y < (int)g[x].size(); y++) {
      edge &e = edg[g[x][y]];
      if (dist[x] + 1 == dist[e.to]) {
        long long minn = min(cp, e.capacity - e.flow);
        newflow = dfs(e.to, minn);
        if (newflow > 0) {
          e.flow += newflow;
          edg[g[x][y] ^ 1].flow -= newflow;
          flow += newflow;
          cp -= newflow;
          if (cp == 0) {
            break;
          }
        }
      }
    }
    return flow;
  }
  long long Dinic() {
    long long flow = 0;
    while (bfs()) {
      memset(cur, 0, sizeof(cur));
      flow += dfs(s, 10000000000ll);
    }
    return flow;
  }
};
Maxflow mf;
int n1, n2, m;
int deg[4111];
vector<int> ans[4111];
int main() {
  int i, j;
  scanf("%d%d%d", &n1, &n2, &m);
  mf.s = 0, mf.t = 4111 - 1;
  for (i = 0; i < m; ++i) {
    int v1, v2;
    scanf("%d%d", &v1, &v2);
    mf.addedge(v1, v2 + n1, 1, i + 1);
    ++deg[v1], ++deg[v2 + n1];
  }
  int k = deg[1];
  for (i = 2; i <= n1 + n2; ++i) {
    k = min(deg[i], k);
  }
  for (i = 1; i <= n1; ++i) {
    mf.addedge(mf.s, i, deg[i] - k, -1);
  }
  for (i = 1; i <= n2; ++i) {
    mf.addedge(n1 + i, mf.t, deg[i + n1] - k, -1);
  }
  int flow = 0;
  for (i = k; i >= 0; --i) {
    flow += mf.Dinic();
    for (auto &e : mf.edg) {
      if (e.from <= n1 && e.from >= 1 && e.to <= n1 + n2 && e.to >= n1 + 1) {
        if (e.flow == 0 && e.capacity == 1) {
          ans[i].push_back(e.id);
        }
      }
    }
    for (j = 1; j <= n1; ++j) {
      mf.addedge(mf.s, j, 1, -1);
    }
    for (j = 1; j <= n2; ++j) {
      mf.addedge(n1 + j, mf.t, 1, -1);
    }
  }
  for (i = 0; i <= k; ++i) {
    printf("%d", (int)ans[i].size());
    for (auto v : ans[i]) {
      printf(" %d", v);
    }
    printf("\n");
  }
  return 0;
}