#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, q;
  cin >> n;
  vector<long long> v;
  for (long long i = 0; i < n; i++) {
    long long temp;
    cin >> temp;
    v.push_back(temp);
  }
  cin >> q;
  while (q--) {
    long long a, b, sum = 0, prev_sum = 0;
    bool flag = false;
    cin >> a >> b;
    int pos = find(v.begin(), v.end(), a) - v.begin();
    if (pos < v.size()) {
      flag = true;
      for (long long i = 0; i < v.size(); i++)
        if (v[i] == a) v[i] = b;
      for (long long i = 0; i < v.size(); i++) sum += v[i];
      prev_sum = sum;
    } else {
      if (flag)
        sum = prev_sum;
      else {
        for (long long i = 0; i < v.size(); i++) sum += v[i];
        prev_sum = sum;
      }
    }
    cout << sum << endl;
  }
}
