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;
vector<bool> edgeUsed;
vector<pair<int, int>> edges;
vector<vector<pair<int, int>>> adj1;
vector<vector<pair<int, int>>> adj2;
vector<int> adjacent1;
vector<int> adjacent2;
vector<bool> onPath1;
vector<bool> onPath2;
vector<int> undo1;
vector<int> undo2;
int k = 0;
bool augment2(int v, int p, bool incr);
bool augment1(int v, int p, bool incr) {
  if (onPath1[v]) return false;
  onPath1[v] = true;
  undo1.push_back(v);
  if (adjacent1[v] < k && !incr) {
    adjacent1[v]++;
    return true;
  }
  for (auto &w : adj1[v]) {
    if (w.first == p) continue;
    if (edgeUsed[w.second] == incr) continue;
    if (augment2(w.first, v, !incr)) {
      edgeUsed[w.second] = edgeUsed[w.second] ^ true;
      if (p == -1) adjacent1[v]++;
      return true;
    }
  }
  return false;
}
bool augment2(int v, int p, bool incr) {
  if (onPath2[v]) return false;
  onPath2[v] = true;
  undo2.push_back(v);
  if (adjacent2[v] < k && !incr) {
    adjacent2[v]++;
    return true;
  }
  for (auto &w : adj2[v]) {
    if (w.first == p) continue;
    if (edgeUsed[w.second] == incr) continue;
    if (augment1(w.first, v, !incr)) {
      edgeUsed[w.second] = edgeUsed[w.second] ^ true;
      if (p == -1) adjacent2[v]++;
      return true;
    }
  }
  return false;
}
bool undo(bool res) {
  while (undo1.size()) {
    onPath1[undo1.back()] = false;
    undo1.pop_back();
  }
  while (undo2.size()) {
    onPath2[undo2.back()] = false;
    undo2.pop_back();
  }
  return res;
}
int main() {
  int n1, n2, m;
  cin >> n1 >> n2 >> m;
  adj1.resize(n1);
  adjacent1.resize(n1);
  onPath1.resize(n1);
  adj2.resize(n2);
  adjacent2.resize(n2);
  onPath2.resize(n2);
  edges.resize(m);
  edgeUsed.resize(m);
  for (int i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b;
    --a;
    --b;
    edges[i] = {a, b};
    adj1[a].emplace_back(b, i);
    adj2[b].emplace_back(a, i);
  }
  long long mindeg = m;
  for (int i = 0; i < n1; ++i) mindeg = min<int>(mindeg, adj1[i].size());
  for (int i = 0; i < n2; ++i) mindeg = min<int>(mindeg, adj2[i].size());
  for (k = 0; k <= mindeg; ++k) {
    for (int i = 0; i < n1; ++i)
      while (adjacent1[i] < k) {
        if (!undo(augment1(i, -1, true))) break;
      }
    for (int i = 0; i < n2; ++i)
      while (adjacent2[i] < k) {
        if (!undo(augment2(i, -1, true))) break;
      }
    set<int> eout;
    for (int i = 0; i < n1; ++i) {
      int extraNeed = k - adjacent1[i];
      for (auto &w : adj1[i]) {
        if (edgeUsed[w.second])
          eout.insert(w.second);
        else if (extraNeed > 0) {
          eout.insert(w.second);
          --extraNeed;
        }
      }
    }
    for (int i = 0; i < n2; ++i) {
      int extraNeed = k - adjacent2[i];
      for (auto &w : adj2[i]) {
        if (edgeUsed[w.second])
          eout.insert(w.second);
        else if (extraNeed > 0) {
          eout.insert(w.second);
          --extraNeed;
        }
      }
    }
    cout << eout.size();
    for (auto &x : eout) cout << " " << x + 1;
    cout << endl;
  }
}