#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using ull = unsigned long long;
int gcd(int x, int y);
int fac(ll n, vector<int> num);
const int INF = 1001001001;
const int mod = 1000000007;
struct mint {
  ll x;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const { return mint(*this) += a; }
  mint operator-(const mint a) const { return mint(*this) -= a; }
  mint operator*(const mint a) const { return mint(*this) *= a; }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }
  mint inv() const { return pow(mod - 2); }
  mint& operator/=(const mint a) { return *this *= a.inv(); }
  mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }
int main() {
  int n, q;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  cin >> q;
  vector<int> b(q);
  vector<int> c(q);
  for (int i = 0; i < q; i++) cin >> b[i] >> c[i];
  vector<int> num(100001);
  ll ans = 0;
  for (int i = 0; i < n; i++) {
    ans += a[i];
    num[a[i]]++;
  }
  for (int i = 0; i < q; i++) {
    ans -= b[i] * num[b[i]];
    ans += c[i] * num[b[i]];
    num[c[i]] += num[b[i]];
    num[b[i]] = 0;
    cout << ans << endl;
  }
  return 0;
}
int gcd(int x, int y) {
  int num[3];
  num[0] = (x > y) ? x : y;
  num[1] = (x <= y) ? x : y;
  num[2] = num[0] % num[1];
  while (num[2]) {
    num[0] = num[1];
    num[1] = num[2];
    num[2] = num[0] % num[1];
  }
  return num[1];
}
int fac(ll n, vector<int> num) {
  ll kazu = n;
  for (int i = 2; i <= sqrt(n); i++) {
    while (1) {
      if (kazu % i != 0) break;
      kazu /= i;
      num[i]++;
    }
  }
  if (kazu == n && n != 1) return 1;
  int ans = 0;
  if (kazu != 1) ans++;
  for (int i = 2; i <= sqrt(n); i++) {
    for (int j = 1; j <= num[i]; j++) {
      num[i] -= j;
      ans++;
    }
  }
  return ans;
}
