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 MAXO = 1e9;
int node, edge;
int src, des;
vector<int> adjl[4010], rc[4010];
vector<int> rev_idx[4010], tim[4010];
void add_edge(int u, int v, int w, int i = 0) {
  adjl[u].push_back(v);
  adjl[v].push_back(u);
  rc[u].push_back(w);
  tim[u].push_back(i);
  rc[v].push_back(0);
  tim[v].push_back(i);
  rev_idx[u].push_back(adjl[v].size() - 1);
  rev_idx[v].push_back(adjl[u].size() - 1);
}
int lev[4010];
int vis[4010];
bool dinic_bfs() {
  memset(vis, 0, sizeof(vis));
  memset(lev, 0, sizeof(lev));
  lev[src] = 0;
  vis[src] = 1;
  queue<int> myq;
  myq.push(src);
  while (!myq.empty()) {
    int u = myq.front();
    myq.pop();
    int sz = adjl[u].size();
    for (int i = 0; i <= sz - 1; i++) {
      int v = adjl[u][i];
      if (rc[u][i] == 0) {
        continue;
      }
      if (vis[v] == 0) {
        vis[v] = 1;
        lev[v] = lev[u] + 1;
        myq.push(v);
      }
    }
  }
  if (vis[des]) {
    return 1;
  }
  return 0;
}
int shuru[4010];
int dinic_dfs(int u, int flow) {
  if (u == des) {
    return flow;
  }
  for (int i = shuru[u]; i <= (int)adjl[u].size() - 1; i++) {
    shuru[u] = i;
    int v = adjl[u][i];
    if ((lev[v] == lev[u] + 1) && (rc[u][i])) {
      int ff = dinic_dfs(v, min(flow, rc[u][i]));
      if (ff) {
        rc[u][i] -= ff;
        rc[v][rev_idx[u][i]] += ff;
        return ff;
      }
    }
  }
  shuru[u] = adjl[u].size();
  return 0;
}
int dinic() {
  int ans = 0;
  while (dinic_bfs()) {
    memset(shuru, 0, sizeof(shuru));
    while (1) {
      int ff = dinic_dfs(src, MAXO);
      if (ff == 0) break;
      ans += ff;
    }
  }
  return ans;
}
int D1[4010], D2[4010];
pair<int, int> ed[4010];
int mopa[2005][2005];
vector<int> ans[4010];
int main() {
  ios::sync_with_stdio(false);
  int n1, n2, m, low;
  cin >> n1 >> n2 >> m;
  src = 0;
  des = n1 + n2 + 1;
  for (int i = 1; i <= m; i++) cin >> ed[i].first >> ed[i].second;
  for (int i = 1; i <= m; i++)
    D1[ed[i].first]++, D2[ed[i].second]++, mopa[ed[i].first][ed[i].second] = i;
  low = D1[1];
  for (int i = 1; i <= n1; i++) low = min(D1[i], low);
  for (int i = 1; i <= n2; i++) low = min(D2[i], low);
  for (int i = 1; i <= n1; i++) add_edge(src, i, D1[i] - low);
  for (int i = 1; i <= n2; i++) add_edge(i + n1, des, D2[i] - low);
  for (int i = 1; i <= m; i++) {
    pair<int, int> k = ed[i];
    add_edge(k.first, k.second + n1, 1, i);
  }
  for (int oo = 0; oo <= low; oo++) {
    dinic();
    for (int chao = 1; chao <= n1; chao++) {
      int u = chao;
      for (int i = 0; i <= (int)adjl[u].size() - 1; i++) {
        int v = adjl[u][i];
        if (v != src && v != des && rc[u][i])
          ans[low - oo].push_back(tim[u][i]);
      }
    }
    int u = src;
    for (int i = 0; i <= (int)adjl[u].size() - 1; i++) rc[u][i]++;
    for (int i = 1; i <= n2; i++) rc[i + n1][0]++;
  }
  for (int oo = 0; oo <= low; oo++) {
    cout << ans[oo].size() << ' ';
    for (auto x : ans[oo]) cout << x << ' ';
    cout << endl;
  }
  return 0;
}