#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
using namespace std;
inline bool equals(long double a, long double b) { return fabs(a - b) < 1e-9; }
inline long long gcd(long long a, long long b) {
  a = abs(a);
  b = abs(b);
  while (a > 0 && b > 0) (a > b ? a %= b : b %= a);
  return (a == 0 ? b : a);
}
inline long long power(long long x, long long n, long long m = LLONG_MAX) {
  long long res = 1;
  x = (x % m + m) % m;
  while (n) {
    if (n & 1) res = (res * x) % m;
    x = (x * x) % m;
    n >>= 1;
  }
  return res;
}
void solve() {
  long long n;
  cin >> n;
  vector<long long> v(10 ^ 5, 0);
  long long sum = 0;
  for (long long i = 0; i < n; i++) {
    long long temp;
    cin >> temp;
    sum += temp;
    v[temp]++;
  }
  long long q;
  cin >> q;
  vector<pair<long long, long long> > p;
  for (long long i = 0; i < q; i++) {
    long long f, s;
    cin >> f >> s;
    p.push_back(make_pair(f, s));
  }
  long long ans = sum;
  for (long long i = 0; i < q; i++) {
    long long temp;
    temp = v[p[i].first];
    ans = (ans - (temp * p[i].first) + (temp * p[i].second));
    v[p[i].second] += temp;
    v[p[i].first] = 0;
    cout << ans << "\n";
  }
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t = 1;
  for (long long i = 1; i <= t; ++i) {
    solve();
  };
  return 0;
}
