#include <bits/stdc++.h>
using namespace std;
template <class T>
void say(bool val, T yes, T no) {
  cout << (val ? yes : no) << "\n";
}
void say(bool val, string yes = "Yes", string no = "No") {
  say<string>(val, yes, no);
}
template <class T>
void chmin(T &a, T b) {
  if (a > b) a = b;
}
template <class T>
void chmax(T &a, T b) {
  if (a < b) a = b;
}
template <class T>
T gcd(T n, T m) {
  return n ? gcd(m % n, n) : m;
}
template <class T>
T lcm(T n, T m) {
  int g = gcd(n, m);
  return n * m / g;
}
template <class T>
void unique(std::vector<T> &v) {
  std::sort(v.begin(), v.end());
  v.erase(std::unique(v.begin(), v.end()), v.end());
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  map<long long int, long long int> mp;
  long long int sum = 0;
  for (int i = 0; i < n; i++) {
    long long int a;
    cin >> a;
    mp[a]++;
    sum += a;
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    long long int b, c;
    cin >> b >> c;
    sum += mp[b] * (c - b);
    cout << sum << endl;
    mp[c] += mp[b];
  }
}
