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;
struct Edge {
  int from, to, cap, flow, index, global_index;
  Edge(int from, int to, int cap, int flow, int index, int global_index)
      : from(from),
        to(to),
        cap(cap),
        flow(flow),
        index(index),
        global_index(global_index) {}
  long long rcap() { return cap - flow; }
};
struct Dinic {
  int N;
  vector<vector<Edge> > G;
  vector<vector<Edge *> > Lf;
  vector<int> layer;
  vector<int> Q;
  Dinic(int N) : N(N), G(N), Q(N) {}
  void AddEdge(int from, int to, int cap, int global_index) {
    if (from == to) return;
    G[from].push_back(Edge(from, to, cap, 0, G[to].size(), global_index));
    G[to].push_back(Edge(to, from, 0, 0, G[from].size() - 1, global_index));
  }
  long long BlockingFlow(int s, int t) {
    layer.clear();
    layer.resize(N, -1);
    layer[s] = 0;
    Lf.clear();
    Lf.resize(N);
    int head = 0, tail = 0;
    Q[tail++] = s;
    while (head < tail) {
      int x = Q[head++];
      for (int i = 0; i < G[x].size(); i++) {
        Edge &e = G[x][i];
        if (e.rcap() <= 0) continue;
        if (layer[e.to] == -1) {
          layer[e.to] = layer[e.from] + 1;
          Q[tail++] = e.to;
        }
        if (layer[e.to] > layer[e.from]) {
          Lf[e.from].push_back(&e);
        }
      }
    }
    if (layer[t] == -1) return 0;
    long long totflow = 0;
    vector<Edge *> P;
    while (!Lf[s].empty()) {
      int curr = P.empty() ? s : P.back()->to;
      if (curr == t) {
        long long amt = P.front()->rcap();
        for (int i = 0; i < P.size(); ++i) {
          amt = min(amt, P[i]->rcap());
        }
        totflow += amt;
        for (int i = P.size() - 1; i >= 0; --i) {
          P[i]->flow += amt;
          G[P[i]->to][P[i]->index].flow -= amt;
          if (P[i]->rcap() <= 0) {
            Lf[P[i]->from].pop_back();
            P.resize(i);
          }
        }
      } else if (Lf[curr].empty()) {
        P.pop_back();
        for (int i = 0; i < N; ++i)
          for (int j = 0; j < Lf[i].size(); ++j)
            if (Lf[i][j]->to == curr) Lf[i].erase(Lf[i].begin() + j);
      } else {
        P.push_back(Lf[curr].back());
      }
    }
    return totflow;
  }
  long long GetMaxFlow(int s, int t) {
    long long totflow = 0;
    while (long long flow = BlockingFlow(s, t)) totflow += flow;
    return totflow;
  }
};
int n, m, e, a, b;
const int N = 10010;
vector<int> answer[N];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> m >> e;
  struct Dinic dinic(n + m + 2);
  for (int i = 1; i <= e; ++i) {
    cin >> a >> b;
    dinic.AddEdge(a, n + b, 1, i);
  }
  size_t minDegree = 0x7fffffff;
  for (int i = 1; i <= n + m; ++i) {
    minDegree = min(minDegree, dinic.G[i].size());
  }
  for (int i = 1; i <= n; ++i) {
    dinic.AddEdge(0, i, 0, -1);
  }
  for (int i = 1; i <= m; ++i) {
    dinic.AddEdge(i + n, n + m + 1, 0, -1);
  }
  for (int i = minDegree; i > 0; --i) {
    for (int j = 0; j < n; ++j) {
      dinic.G[0][j].cap = dinic.G[j + 1].size() - i - 1;
    }
    for (int j = 0; j < m; ++j) {
      int k = dinic.G[n + j + 1].size() - 1;
      dinic.G[n + j + 1][k].cap = k - i;
    }
    dinic.GetMaxFlow(0, n + m + 1);
    for (int j = 1; j <= n; ++j) {
      for (int k = 0; k < dinic.G[j].size(); ++k) {
        if (dinic.G[j][k].cap > 0 and dinic.G[j][k].cap != dinic.G[j][k].flow) {
          answer[i].push_back(dinic.G[j][k].global_index);
        }
      }
    }
  }
  for (int i = 0; i <= minDegree; ++i) {
    cout << answer[i].size();
    for (int j = 0; j < answer[i].size(); ++j) {
      cout << " " << answer[i][j];
    }
    cout << "\n";
  }
  return 0;
}