#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
const ll INF = 1001001001;
ll gcd(ll a, ll b) {
  if (a % b == 0) {
    return (b);
  } else {
    return (gcd(b, a % b));
  }
}
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
int main() {
  cout << fixed << setprecision(10);
  ll N;
  cin >> N;
  vector<ll> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec[i];
  }
  ll Q;
  cin >> Q;
  vector<ll> vecB(Q);
  vector<ll> vecC(Q);
  for (int i = 0; i < Q; i++) {
    cin >> vecB[i] >> vecC[i];
  }
  for (int i = 0; i < Q; i++) {
    ll sum = 0;
    for (int j = 0; j < N; j++) {
      if (vec[j] == vecB[i]) {
        vec[j] = vecC[i];
      }
      sum += vec[j];
    }
    cout << sum << endl;
  }
}
