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