#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 5;
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long n;
  cin >> n;
  vector<long long> a(n);
  for (long long &e : a) cin >> e;
  long long q;
  cin >> q;
  while (q--) {
    long long b, c;
    long long cnt = 0;
    cin >> b >> c;
    for (long long i = 0; i < n; i++) {
      if (a[i] == b) {
        a[i] = c;
        cnt += c;
      } else
        cnt += a[i];
    }
    cout << cnt << "\n";
  }
}
