#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
ll gcd(ll a, ll b) {
  ll tmp;
  if (b > a) {
    tmp = a;
    a = b;
    b = tmp;
  }
  while (a % b != 0) {
    tmp = b;
    b = a % b;
    a = tmp;
  }
  return b;
}
const int MAX = 2000;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % 1000000007;
    inv[i] = 1000000007 - inv[1000000007 % i] * (1000000007 / i) % 1000000007;
    finv[i] = finv[i - 1] * inv[i] % 1000000007;
  }
}
long long COM(int n, int k) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % 1000000007) % 1000000007;
}
void sosuu(ll n, vector<ll> &v) {
  vector<ll> num(n, 0);
  for (ll i = (1); i <= (sqrt(n)); i++) {
    if (num[i] == 0) {
      for (ll j = (0); j <= (n / i); j++) {
        num[i + (j * i)] = 1;
      }
    }
  }
  for (ll i = 0; i < (ll)(n); i++) {
    if (num[i] == 0) v.push_back(i + 1);
  }
}
ll GetDigit(ll num) {
  ll digit = 0;
  while (num != 0) {
    num /= 10;
    digit++;
  }
  return digit;
}
ll power(ll a, ll b) {
  ll ans = 1;
  if (b % 2 == 0) {
    for (ll i = 0; i < (ll)(b / 2); i++) {
      ans *= a;
      if (ans > 1000000000) {
        return -1;
      }
    }
    return ans * ans;
  } else {
    b = b / 2;
    for (ll i = 0; i < (ll)(b); i++) {
      ans *= a;
      if (ans > 1000000000) {
        return -1;
      }
    }
    return ans * ans * a;
  }
}
vector<pair<long long, long long> > prime_factorize(long long N) {
  vector<pair<long long, long long> > res;
  for (long long a = 2; a * a <= N; ++a) {
    if (N % a != 0) continue;
    long long ex = 0;
    while (N % a == 0) {
      ++ex;
      N /= a;
    }
    res.push_back({a, ex});
  }
  if (N != 1) res.push_back({N, 1});
  return res;
}
int main(void) {
  ll n;
  cin >> n;
  vector<ll> v(n);
  ll sum = 0;
  map<ll, ll> m;
  for (ll i = 0; i < (ll)(n); i++) {
    ll x;
    cin >> x;
    v[i] = x;
    sum += x;
    m[x]++;
  }
  ll q;
  cin >> q;
  vector<ll> ans(q);
  for (ll i = 0; i < (ll)(q); i++) {
    ll x, y;
    cin >> x >> y;
    decltype(m)::iterator it = m.find(x);
    if (it != m.end()) {
      m[y] += m[x];
      sum -= x * m[x];
      sum += m[x] * y;
    }
    ans[i] = sum;
  }
  for (ll i = 0; i < (ll)(q); i++) cout << ans[i] << endl;
  return 0;
}
