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