#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, i;
  cin >> n;
  long long a[n];
  long long sum = 0;
  vector<long long> v;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
  }
  long long q;
  cin >> q;
  long long b, c;
  for (i = 0; i < q; i++) {
    cin >> b >> c;
    unordered_map<long long, long long> hm;
    for (long long j = 0; j < n; j++) {
      hm[a[j]]++;
    }
    sum = sum + hm[b] * (c - b);
    replace(a, a + n, b, c);
    cout << sum << "\n";
  }
  return 0;
}
