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;
int Q, N, M, K, L;
int IND[4005];
int src, dst;
vector<int> dinicLevel;
struct NEdge {
  int dst, capacity, rev, index;
  bool is_rev;
};
vector<NEdge> NG[4005];
vector<int> dinic_pos;
void AddNEdge(int u, int v, int idx, int cap) {
  NG[u].push_back(NEdge{v, cap, (int)NG[v].size(), idx, false});
  NG[v].push_back(NEdge{u, 0, (int)NG[u].size() - 1, idx, true});
}
bool DinicBFS() {
  dinicLevel.clear();
  dinicLevel.resize(4005 + 5, -1);
  for (int i = 0; i < 4005 + 5; i++) dinicLevel[i] = -1;
  dinicLevel[src] = 0;
  queue<int> q;
  q.push(src);
  while (!q.empty()) {
    int cur = q.front();
    q.pop();
    for (int i = 0; i < NG[cur].size(); i++) {
      auto& next = NG[cur][i];
      if (dinicLevel[next.dst] == -1 && next.capacity > 0) {
        dinicLevel[next.dst] = dinicLevel[cur] + 1;
        q.push(next.dst);
      }
    }
  }
  return dinicLevel[dst] != -1;
}
int DinicDFS(int cur, int flow) {
  if (cur == dst) return flow;
  if (flow == 0) return 0;
  int ret = 0;
  for (int& i = dinic_pos[cur]; i < NG[cur].size(); i++) {
    auto& next = NG[cur][i];
    if (dinicLevel[next.dst] == dinicLevel[cur] + 1 && next.capacity > 0) {
      int subret = DinicDFS(next.dst, min(next.capacity, flow - ret));
      if (subret > 0) {
        next.capacity -= subret;
        NG[next.dst][next.rev].capacity += subret;
        ret += subret;
      }
      if (ret == flow) break;
    }
  }
  return ret;
}
void IncFlow(int f) {
  for (int i = 0; i < NG[src].size(); i++) {
    auto& e = NG[src][i];
    e.capacity += f;
  }
  for (int i = 0; i < NG[dst].size(); i++) {
    auto& e = NG[dst][i];
    auto& re = NG[e.dst][e.rev];
    re.capacity += f;
  }
}
int main() {
  std::ios::sync_with_stdio(false);
  vector<vector<int> > ret;
  cin >> N >> M >> K;
  src = 4005 - 2;
  dst = 4005 - 1;
  for (int i = 0; i < N; i++) AddNEdge(src, i, 0, 0);
  for (int i = 0; i < M; i++) AddNEdge(2000 + i, dst, 0, 0);
  for (int i = 0; i < K; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    b += 2000;
    IND[a]++;
    IND[b]++;
    AddNEdge(a, b, i, 1);
  }
  int min_deg = 100000000;
  for (int i = 0; i < N; i++) min_deg = min(IND[i], min_deg);
  for (int i = 2000; i < 2000 + M; i++) min_deg = min(IND[i], min_deg);
  for (int i = 0; i < NG[src].size(); i++) {
    auto& e = NG[src][i];
    if (e.is_rev) continue;
    e.capacity += IND[e.dst] - min_deg;
  }
  for (int i = 0; i < NG[dst].size(); i++) {
    auto& e = NG[dst][i];
    if (!e.is_rev) continue;
    auto& re = NG[e.dst][e.rev];
    re.capacity += IND[e.dst] - min_deg;
  }
  for (int i = 0; i <= min_deg; i++) {
    int f = 0;
    while (DinicBFS()) {
      dinic_pos.clear();
      dinic_pos.resize(4005, 0);
      int t;
      while (t = DinicDFS(src, 100000000)) f += t;
    }
    ret.emplace_back();
    auto& subret = ret.back();
    for (int i = 0; i < 2000; i++) {
      auto& g = NG[i];
      for (auto& e : g) {
        if (e.is_rev) continue;
        if (e.capacity == 0) continue;
        subret.push_back(e.index + 1);
      }
    }
    IncFlow(1);
  }
  for (int i = ret.size() - 1; i >= 0; i--) {
    auto& v = ret[i];
    cout << v.size() << " ";
    for (auto x : v) cout << x << " ";
    cout << "\n";
  }
  cin >> N;
}