#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;
}
