#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lli = long long int;
using ld = long double;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  ll n, q, a, b;
  cin >> n;
  ll ar[n];
  for (int i = 0; i < n; i++) cin >> ar[i];
  cin >> q;
  ll s = 0;
  while (q--) {
    cin >> a >> b;
    for (int i = 0; i < n; i++) {
      if (ar[i] == a) {
        ar[i] = b;
      }
      s += ar[i];
    }
    cout << s << "\n";
    s = 0;
  }
  return 0;
}
