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>
int res[4002][4002];
int SRC, SNK;
int flow = 0;
std::vector<std::pair<int, int> > elist;
std::vector<int> edges[4002];
int deg1[2000];
int deg2[2000];
bool vis[4002];
bool dfs(int node) {
  if (node == SNK) return true;
  if (vis[node]) return false;
  vis[node] = true;
  for (int adj : edges[node]) {
    if (res[node][adj]) {
      if (dfs(adj)) {
        res[node][adj]--;
        res[adj][node]++;
        return true;
      }
    }
  }
  return false;
}
std::vector<std::vector<int> > ans;
int main() {
  int N1, N2, M;
  scanf("%d %d %d", &N1, &N2, &M);
  SRC = N1 + N2;
  SNK = N1 + N2 + 1;
  for (int i = 0; i < N1; i++) {
    edges[SRC].push_back(i);
    edges[i].push_back(SRC);
  }
  for (int i = 0; i < N2; i++) {
    edges[SNK].push_back(N1 + i);
    edges[N1 + i].push_back(SNK);
  }
  for (int i = 0; i < M; i++) {
    int U, V;
    scanf("%d %d", &U, &V);
    U--, V--;
    elist.emplace_back(U, V);
    edges[U].push_back(N1 + V);
    edges[N1 + V].push_back(U);
    res[U][N1 + V]++;
    deg1[U]++;
    deg2[V]++;
  }
  int mindeg = 1e9;
  for (int i = 0; i < N1; i++) {
    mindeg = std::min(mindeg, deg1[i]);
  }
  for (int i = 0; i < N2; i++) {
    mindeg = std::min(mindeg, deg2[i]);
  }
  for (int i = 0; i < N1; i++) {
    res[SRC][i] = deg1[i] - mindeg;
  }
  for (int i = 0; i < N2; i++) {
    res[N1 + i][SNK] = deg2[i] - mindeg;
  }
  for (int k = 0; k <= mindeg; k++) {
    while (true) {
      std::fill(vis, vis + N1 + N2 + 2, false);
      if (!dfs(SRC)) break;
      flow++;
    }
    std::vector<int> ids;
    for (int i = 0; i < elist.size(); i++) {
      auto e = elist[i];
      if (res[e.first][N1 + e.second]) {
        res[e.first][N1 + e.second]--;
        ids.push_back(i);
      }
    }
    ans.emplace_back(ids);
    for (int i : ids) {
      auto e = elist[i];
      res[e.first][N1 + e.second]++;
    }
    for (int i = 0; i < N1; i++) {
      res[SRC][i]++;
    }
    for (int i = 0; i < N2; i++) {
      res[N1 + i][SNK]++;
    }
  }
  std::reverse(ans.begin(), ans.end());
  for (auto a : ans) {
    printf("%d", (int)a.size());
    for (int i : a) {
      printf(" %d", i + 1);
    }
    printf("\n");
  }
  return 0;
}