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>
const int inf = 0x3F3F3F3F;
class maximal_flow {
  struct edge {
    int from, to, cap, flow;
    edge(int _from, int _to, int _cap)
        : from(_from), to(_to), cap(_cap), flow(0) {}
  };
  std::vector<edge> edges;
  std::vector<int> adj[4010 + 5];
  int dist[4010 + 5];
  bool vis[4010 + 5];
  int cur[4010 + 5];
  int s, t;
  bool bfs() {
    std::queue<int> q;
    memset(dist, 0x3F, sizeof(dist));
    memset(vis, 0, sizeof(vis));
    q.push(s);
    dist[s] = 0;
    vis[s] = true;
    while (!q.empty()) {
      int current = q.front();
      q.pop();
      for (int ei : adj[current]) {
        const edge& eg = edges[ei];
        if (!vis[eg.to] && eg.cap > eg.flow) {
          dist[eg.to] = dist[current] + 1;
          vis[eg.to] = true;
          q.push(eg.to);
        }
      }
    }
    return vis[t];
  }
  int augment(int current, int res) {
    if (current == t || res == 0) return res;
    int flow = 0, tmp = 0;
    for (int& i = cur[current]; i < (int)adj[current].size(); ++i) {
      edge& e = edges[adj[current][i]];
      if (dist[e.to] == dist[current] + 1) {
        tmp = augment(e.to, std::min(res, e.cap - e.flow));
        if (tmp > 0) {
          e.flow += tmp;
          edges[adj[current][i] ^ 1].flow -= tmp;
          flow += tmp;
          res -= tmp;
          if (res == 0) break;
        }
      }
    }
    return flow;
  }

 public:
  void init(int n) {
    edges.clear();
    for (int i = 0; i <= n; ++i) adj[i].clear();
  }
  int add_edge(int from, int to, int cap) {
    edges.push_back(edge(from, to, cap));
    edges.push_back(edge(to, from, 0));
    int eid = (int)edges.size() - 2;
    adj[from].push_back(eid);
    adj[to].push_back(eid ^ 1);
    return eid;
  }
  void remove_edge(int eid) {
    edges[eid].cap = edges[eid].flow = 0;
    edges[eid ^ 1].cap = edges[eid ^ 1].flow = 0;
  }
  void clear_flow() {
    for (edge& e : edges) e.flow = 0;
  }
  int run(int src, int target) {
    s = src;
    t = target;
    int f = 0;
    while (bfs()) {
      memset(cur, 0, sizeof(cur));
      f += augment(src, inf);
    }
    return f;
  }
  int flow_on(int eid) const { return edges[eid].flow; }
};
maximal_flow f;
int outdeg[2005], indeg[2005];
std::pair<int, int> links[2005];
int n1, n2, m;
void solve(int k) {
  f.init(n1 + n2 + 4);
  std::unordered_map<int, int> lid;
  int s = 0, t = n1 + n2 + 1;
  int ss = n1 + n2 + 2, tt = n1 + n2 + 3;
  for (int i = 1; i <= m; ++i) {
    const auto& [u, v] = links[i];
    lid[f.add_edge(u, v + n1, 1)] = i;
  }
  for (int i = 1; i <= n1; ++i) f.add_edge(s, i, inf);
  for (int i = 1; i <= n2; ++i) f.add_edge(i + n1, t, inf);
  int tse = f.add_edge(t, s, inf);
  for (int i = 1; i <= n1; ++i) f.add_edge(ss, i, k);
  for (int i = 1; i <= n2; ++i) f.add_edge(i + n1, tt, k);
  f.add_edge(s, tt, k * n1);
  f.add_edge(ss, t, k * n2);
  int flow = f.run(ss, tt);
  int sscap = k * (n1 + n2);
  assert(flow <= sscap);
  if (flow < sscap) {
    puts("0");
    return;
  }
  f.remove_edge(tse);
  f.run(t, s);
  std::vector<int> cov;
  for (const auto& [ef, e] : lid) {
    if (f.flow_on(ef) == 1) cov.push_back(e);
  }
  printf("%d", (int)cov.size());
  for (int item : cov) printf(" %d", item);
  printf("\n");
}
int main(int argc, char* argv[]) {
  scanf("%d%d%d", &n1, &n2, &m);
  for (int i = 1; i <= m; ++i) {
    scanf("%d%d", &links[i].first, &links[i].second);
    ++outdeg[links[i].first];
    ++indeg[links[i].second];
  }
  int mindeg = INT_MAX;
  for (int i = 1; i <= n1; ++i) mindeg = std::min(mindeg, outdeg[i]);
  for (int i = 1; i <= n2; ++i) mindeg = std::min(mindeg, indeg[i]);
  for (int k = 0; k <= mindeg; ++k) solve(k);
  return 0;
}