#include <bits/stdc++.h>
using namespace std;
int main() {
  {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
  };
  long long n;
  cin >> n;
  vector<long long> v;
  for (long long i = 0, temp; i < n; i++) {
    cin >> temp;
    v.push_back(temp);
  };
  long long q;
  cin >> q;
  for (long long i = 0; i < q; i++) {
    long long a, b, su = 0;
    cin >> a >> b;
    for (long long i = 0; i < n; i++) {
      if (v[i] == a) v[i] = b;
      su = su + v[i];
    }
    cout << su << "\n";
  }
  return 0;
}
