#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  unsigned long sum = 0;
  vector<int> a(n);
  for (int i = 0; i < (int)n; i++) cin >> a[i], sum += a[i];
  sort(a.begin(), a.end());
  int q, b, c;
  cin >> q;
  for (int i = 0; i < (int)q; i++) {
    cin >> b >> c;
    int cnt = count(a.begin(), a.end(), b);
    replace(a.begin(), a.end(), b, c);
    sum += (c - b) * cnt;
    cout << sum << endl;
  }
}
