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;
class EdmondKarp {
 public:
  EdmondKarp(int n) : n(n) { capacity.assign(n, vector<int>(n, 0)); }
  void determine_adj() {
    adj.resize(n);
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < n; j++) {
        if (capacity[i][j] || capacity[j][i]) adj[i].push_back(j);
      }
    }
  }
  int maxflow(int s, int t) {
    int flow = 0;
    std::vector<int> parent(n);
    int new_flow;
    while ((new_flow = bfs(s, t, parent))) {
      flow += new_flow;
      int node = t;
      while (node != s) {
        int prev = parent[node];
        capacity[prev][node] -= new_flow;
        capacity[node][prev] += new_flow;
        node = prev;
      }
    }
    return flow;
  }
  int bfs(int s, int t, std::vector<int>& parent) {
    fill(parent.begin(), parent.end(), -1);
    parent[s] = -2;
    std::queue<std::pair<int, int>> q;
    q.push({s, std::numeric_limits<int>::max()});
    while (!q.empty()) {
      int node, flow;
      std::tie(node, flow) = q.front();
      q.pop();
      for (auto next : adj[node]) {
        if (parent[next] == -1 && capacity[node][next]) {
          parent[next] = node;
          int new_flow = std::min(flow, capacity[node][next]);
          if (next == t) return new_flow;
          q.push({next, new_flow});
        }
      }
    }
    return 0;
  }
  int n;
  std::vector<std::vector<int>> capacity;
  std::vector<std::vector<int>> adj;
};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n1, n2, m;
  cin >> n1 >> n2 >> m;
  int n = n1 + n2 + 4;
  vector<pair<int, int>> edges(m);
  vector<int> degree(n1 + n2, 0);
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    u--, v--;
    v += n1;
    edges[i] = {u, v};
    degree[u]++;
    degree[v]++;
  }
  int minDegree = m;
  for (int x : degree) minDegree = min(minDegree, x);
  EdmondKarp ek(n);
  auto fill_capacity = [&](int degree) {
    auto& capacity = ek.capacity;
    for (auto& e : edges) {
      capacity[e.first][e.second] = 0;
      capacity[e.second][e.first] = 0;
    }
    for (auto& e : edges) {
      capacity[e.first][e.second]++;
    }
    for (int u = 0; u < n1; u++) {
      capacity[n - 2][u] = degree;
      capacity[u][n - 2] = 0;
      capacity[n - 4][u] = m;
      capacity[u][n - 4] = 0;
    }
    capacity[n - 2][n - 3] = degree * n2;
    capacity[n - 3][n - 2] = 0;
    for (int v = n1; v < n1 + n2; v++) {
      capacity[v][n - 1] = degree;
      capacity[n - 1][v] = 0;
      capacity[v][n - 3] = m;
      capacity[n - 3][v] = 0;
    }
    capacity[n - 4][n - 1] = degree * n1;
    capacity[n - 1][n - 4] = 0;
    capacity[n - 3][n - 4] = 1;
    capacity[n - 4][n - 3] = 0;
  };
  fill_capacity(1);
  ek.determine_adj();
  cout << 0 << '\n';
  for (int degree = 1; degree <= minDegree; degree++) {
    int L = degree * max(n1, n2) - 1;
    int R = m;
    while (L + 1 < R) {
      int M = (L + R) / 2;
      fill_capacity(degree);
      ek.capacity[n - 3][n - 4] = M;
      int flow = ek.maxflow(n - 2, n - 1);
      if (flow == degree * (n1 + n2))
        R = M;
      else
        L = M;
    }
    fill_capacity(degree);
    ek.capacity[n - 3][n - 4] = R;
    ek.maxflow(n - 2, n - 1);
    cout << R;
    for (int i = 0; i < m; i++) {
      auto [u, v] = edges[i];
      if (ek.capacity[v][u] > 0) {
        cout << " " << i + 1;
        ek.capacity[v][u]--;
      }
    }
    cout << '\n';
  }
}