#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  int n, q;
  cin >> n;
  map<ll, ll> mp;
  vector<ll> a(n);
  for (int i = 0; i < (n); i++) {
    cin >> a[i];
    mp[a[i]]++;
  }
  ll sum = 0;
  cin >> q;
  for (int i = 0; i < (n); i++) sum += a[i];
  for (int i = 0; i < (q); i++) {
    int b, c;
    cin >> b >> c;
    ll x = mp[b];
    sum -= x * b;
    mp[c] += x;
    sum += c * x;
    cout << sum << endl;
  }
  return 0;
}
