#include <iostream> #include <unordered_set> using namespace std; int main() { int start1, start2, n; while (cin >> start1 >> start2 >> n) { unordered_set<int> set; while (n--) { int cur, next; char c; cin >> cur >> c >> next; if (set.count(next) == 0) set.insert(next); else { cout << next << endl; } } } return 0; }