#include <bits/stdc++.h>
using namespace std;
const int INF_INT = 2147483647;
const long long INF_LONG = 9223372036854775807;
using ll = long long;
int main() {
  ll n, q;
  cin >> n;
  map<ll, ll> map;
  ll sum = 0;
  for (int i = 0; i < (int)(n); i++) {
    ll x;
    cin >> x;
    map[x] += x;
    sum += x;
  }
  cin >> q;
  for (int i = 0; i < (int)(q); i++) {
    ll a, b;
    cin >> a >> b;
    ll num = map[a] / a;
    sum -= map[a];
    map[a] = 0;
    map[b] = num * b;
    sum += map[b];
    cout << sum << endl;
  }
}
