#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
using ll = int64_t;
using vi = vector<int>;
using vll = vector<ll>;
long long gcd(long long a, long long b) {
  if (a < b) swap(a, b);
  if (a % b == 0) {
    return (b);
  } else {
    return (gcd(b, a % b));
  }
}
long long lcm(long long a, long long b) { return a * b / gcd(a, b); }
long long bikkuri(long long k) {
  long long sum = 1;
  for (long long i = 1; i <= k; ++i) {
    sum *= i;
  }
  return sum;
}
int main() {
  int n;
  int q;
  ll sum = 0;
  ll count;
  cin >> n;
  vll a(n);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }
  for (int i = 0; i < n; i++) {
    sum += a.at(i);
  }
  cin >> q;
  vll b(q);
  vll c(q);
  for (int i = 0; i < q; i++) {
    cin >> b.at(i) >> c.at(i);
  }
  sort(a.begin(), a.end());
  for (int i = 0; i < q; i++) {
    ll be, ce;
    be = b.at(i);
    ce = c.at(i);
    count = 0;
    for (int j = 0; j < n; j++) {
      if (a.at(j) == be) {
        a.at(j) = ce;
        count++;
      }
    }
    sum += (ce - be) * count;
    cout << sum << endl;
  }
}
