#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int n, q, sum = 0, cnt = 0, num1 = 0, num2 = 0;
  cin >> n;
  long long int a[n], i, b, c;
  vector<long long int> v;
  for (i = 0; i < n; ++i) {
    cin >> a[i];
    sum += a[i];
    v.push_back(a[i]);
  }
  sort(v.begin(), v.end());
  cin >> q;
  while (q--) {
    cin >> b >> c;
    cnt =
        upper_bound(v.begin(), v.end(), b) - lower_bound(v.begin(), v.end(), b);
    sum -= cnt * b;
    sum += cnt * c;
    cout << sum << endl;
    for (i = 0; i < n; ++i) {
      if (v[i] == b) v[i] = c;
    }
  }
  return 0;
}
