#include <bits/stdc++.h>
using namespace std;
long long gcd(long long n, long long m) { return m ? gcd(m, n % m) : n; }
long long lcm(long long n, long long m) { return n / gcd(n, m) * m; }
struct debugger {
  static void call(string::iterator it, string::iterator ed) {}
  template <typename T, typename... aT>
  static void call(string::iterator it, string::iterator ed, T a, aT... rest) {
    string b;
    for (; *it != ','; ++it)
      if (*it != ' ') b += *it;
    cout << b << "=" << a << " ";
    call(++it, ed, rest...);
  }
};
void solve() {
  int n;
  cin >> n;
  vector<int> arr(n);
  long long int sum = 0;
  map<int, int> mp;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    sum += arr[i];
    mp[arr[i]]++;
  }
  int k;
  cin >> k;
  for (int i = 0; i < k; i++) {
    int a, b;
    cin >> a >> b;
    sum -= (mp[a] * a);
    sum += (mp[a] * b);
    mp[b] = mp[b] + mp[a];
    mp.erase(a);
    cout << sum << '\n';
  }
}
int main() { solve(); }
