#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pl = pair<ll, ll>;
using vpl = vector<pl>;
using vvpl = vector<vpl>;
const ll MOD = 1000000007;
const ll MOD9 = 998244353;
const int inf = 1e9 + 10;
const ll INF = 4e18;
const ll dy[9] = {1, 0, -1, 0, 1, 1, -1, -1, 0};
const ll dx[9] = {0, -1, 0, 1, 1, -1, 1, -1, 0};
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int main() {
  ll n;
  cin >> n;
  vl a(n);
  for (ll i = 0; i < n; i++) cin >> a[i];
  vl x(100010, 0);
  for (ll i = 0; i < n; i++) x[a[i]]++;
  ll sum = accumulate((a).begin(), (a).end(), 0);
  ll q;
  cin >> q;
  while (q--) {
    ll b, c;
    cin >> b >> c;
    ll p = x[b];
    x[b] = 0;
    sum -= p * b;
    sum += p * c;
    x[c] += p;
    cout << sum << endl;
  }
}
