#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
int main() {
  ll n, q;
  vector<ll> a;
  ll tmp;
  cin >> n;
  for (ll i = 0; i < (n); i++) {
    cin >> tmp;
    a.push_back(tmp);
  }
  cin >> q;
  ll x, y;
  for (ll i = 0; i < (q); i++) {
    cin >> x >> y;
    ll sum = 0;
    for (ll j = 0; j < (a.size()); j++) {
      if (a[j] == x) a[j] = y;
      sum += a[j];
    }
    cout << sum << endl;
  }
}
