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>
#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
using namespace std;
const int arr = 2e5 + 10;
const int ar = 2e3 + 10;
const long double pi = acos(-1);
const long double eps = 1e-10;
const long long md = 1e9 + 7;
vector<pair<pair<int, int>, int>> reb[arr];
int dist[arr];
bool use[arr];
pair<int, int> pred[arr];
int p[arr];
pair<int, int> kek[arr];
void add_edge(int from, int to, int flow) {
  int e1 = (int)(reb[from].size());
  int e2 = (int)(reb[to].size());
  reb[from].push_back({{to, flow}, e2});
  reb[to].push_back({{from, 0}, e1});
}
int s, t;
bool bfs() {
  for (int i = 0; i <= t; i++) {
    dist[i] = 1e9;
    use[i] = 0;
    pred[i] = {-1, -1};
    p[i] = 0;
  }
  queue<int> q;
  q.push(s);
  use[s] = 1;
  dist[s] = 0;
  while (!q.empty()) {
    int now = q.front();
    q.pop();
    int num = 0;
    for (auto wh : reb[now]) {
      if (!use[wh.first.first] && wh.first.second) {
        use[wh.first.first] = 1;
        dist[wh.first.first] = dist[now] + 1;
        q.push(wh.first.first);
      }
      num++;
    }
  }
  return dist[t] < 1e9;
}
void dfs(int now) {
  use[now] = 1;
  if (use[t]) {
    return;
  }
  for (; p[now] < (int)(reb[now].size());) {
    int to = reb[now][p[now]].first.first;
    if (dist[to] == dist[now] + 1 && reb[now][p[now]].first.second) {
      dfs(to);
      pred[to] = {now, p[now]};
      if (use[t]) {
        return;
      }
    }
    p[now]++;
  }
}
int go_back() {
  int cur;
  cur = t;
  while (cur != s) {
    int from = pred[cur].first;
    int num = pred[cur].second;
    reb[from][num].first.second--;
    reb[cur][reb[from][num].second].first.second++;
    cur = from;
  }
  return 1;
}
int ans = 0;
void max_flow() {
  while (bfs()) {
    for (int i = 0; i <= t; i++) {
      p[i] = 0;
    }
    while (1) {
      for (int i = 0; i <= t; i++) {
        use[i] = 0;
        pred[i] = {-1, -1};
      }
      dfs(s);
      if (!use[t]) {
        break;
      }
      ans += go_back();
    }
  }
}
int cnt1[arr];
int cnt2[arr];
int lol[arr];
int bur[arr];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int n1, n2, m;
  cin >> n1 >> n2 >> m;
  for (int i = 1; i <= m; i++) {
    int u, v;
    cin >> u >> v;
    cnt1[u]++;
    cnt2[v]++;
    bur[i] = v;
    add_edge(u, n1 + v, 1);
    kek[i] = {u, (int)(reb[u].size()) - 1};
  }
  for (int j = 1; j <= n1; j++) {
    add_edge(s, j, 0);
  }
  t = n1 + n2 + 1;
  for (int j = 1; j <= n2; j++) {
    add_edge(n1 + j, t, 0);
  }
  int MAX = min(*min_element(cnt1 + 1, cnt1 + n1 + 1),
                *min_element(cnt2 + 1, cnt2 + n2 + 1));
  cout << 0 << "\n";
  for (int i = 1; i <= MAX; i++) {
    for (auto& j : reb[s]) {
      j.first.second++;
    }
    for (int j = 1; j <= n2; j++) {
      for (auto& k : reb[n1 + j]) {
        if (k.first.first == t) {
          k.first.second++;
        }
      }
    }
    max_flow();
    int c2 = ans;
    int ANSWER = (n1 + n2) * i - c2;
    cout << ANSWER << " ";
    for (int j = 1; j <= n1; j++) {
      lol[j] = i;
    }
    for (int j = 1; j <= n2; j++) {
      lol[n1 + j] = i;
    }
    for (int j = 1; j <= m; j++) {
      if (reb[kek[j].first][kek[j].second].first.second == 0) {
        cout << j << " ";
        lol[kek[j].first]--;
        lol[n1 + bur[j]]--;
      }
    }
    for (int j = 1; j <= m; j++) {
      if (reb[kek[j].first][kek[j].second].first.second == 1) {
        if (lol[kek[j].first] > 0 || lol[n1 + bur[j]] > 0) {
          cout << j << " ";
          lol[kek[j].first]--;
          lol[n1 + bur[j]]--;
        }
      }
    }
    cout << "\n";
  }
}