#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
using ll = long long;
const int INF = 1001001001;
int main() {
  map<int, int> memo;
  int n, q;
  cin >> n;
  vector<int> a(n);
  int sum = 0;
  for (int i = 0; i < (n); i++) {
    cin >> a[i];
    sum += a[i];
    memo[a[i]]++;
  }
  cin >> q;
  int x, y;
  for (int i = 0; i < (q); i++) {
    cin >> x >> y;
    cout << "mw" << memo[x] << endl;
    sum += memo[x] * (y - x);
    memo[y] += memo[x];
    memo.erase(x);
    cout << sum << endl;
  }
  return 0;
}
