#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long n, q;
  cin >> n;
  vector<int> v;
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    v.push_back(x);
  }
  sort(v.begin(), v.end());
  cin >> q;
  for (int i = 0; i < q; ++i) {
    long long b, c;
    long long sum = 0;
    cin >> b >> c;
    vector<int>::iterator it, u;
    it = find(v.begin(), v.end(), b);
    if (it != v.end()) {
      while (it != v.end()) {
        if (*it == b)
          *it = c;
        else
          break;
        it++;
      }
    }
    for (u = v.begin(); u != v.end(); u++) {
      sum += *u;
    }
    cout << sum << "\n";
  }
  return 0;
}
