#include <bits/stdc++.h>
using namespace std;
void ayushmehta651() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
int32_t main() {
  ayushmehta651();
  long long n;
  cin >> n;
  long long a[n];
  for (long long i = 0; i < n; ++i) {
    cin >> a[i];
  }
  long long q;
  cin >> q;
  while (q--) {
    long long b, c;
    cin >> b >> c;
    long long sum = 0;
    for (long long i = 0; i < n; ++i) {
      if (a[i] == b) {
        a[i] = c;
        sum += c;
      } else
        sum += a[i];
    }
    cout << sum << '\n';
  }
  return 0;
}
