#include <bits/stdc++.h>
using namespace std;
struct hash_pair {
  template <class T1, class T2>
  size_t operator()(const pair<T1, T2>& p) const {
    auto hash1 = hash<T1>{}(p.first);
    auto hash2 = hash<T2>{}(p.second);
    return hash1 ^ hash2;
  }
};
int MAXNUM = 5e3 + 5;
vector<int> vis(MAXNUM);
vector<int> pr;
void sieve() {
  pr.push_back(2);
  for (long long i = 3; i < MAXNUM; i += 2)
    if (!vis[i]) {
      pr.push_back(i);
      for (long long j = i * i; j < MAXNUM; j += 2 * i) vis[j] = true;
    }
}
void solve() {
  long long n;
  cin >> n;
  map<long long, long long> m;
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    long long x;
    cin >> x;
    ans += x;
    if (m.find(x) == m.end())
      m[x] = 1;
    else
      m[x]++;
  }
  long long q;
  cin >> q;
  while (q--) {
    long long b, c;
    cin >> b >> c;
    long long cnt = 0;
    if (m.find(b) != m.end()) {
      cnt = m[b];
      ans -= cnt * b;
      ans += cnt * c;
      if (m.find(c) == m.end())
        m[c] = cnt;
      else
        m[c] += cnt;
    }
    cout << ans << endl;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t;
  t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
