#include <bits/stdc++.h>
long long powmod(long long a, long long b) {
  long long res = 1;
  a %= 1000000007;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % 1000000007;
    a = a * a % 1000000007;
  }
  return res;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
bool isprime(long long n) {
  bool flag = true;
  for (long long i = 2; i <= sqrt(n); i++) {
    if (n % i == 0) {
      flag = false;
      break;
    }
  }
  return flag;
}
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  map<int, int> mp;
  int sum = 0;
  for (int i = 0; i < n; i++) {
    if (mp.count(a[i]) == 0)
      mp[a[i]] = 1;
    else
      mp[a[i]] += 1;
    sum += a[i];
  }
  int q;
  cin >> q;
  while (q--) {
    int q, w;
    cin >> q >> w;
    if (mp.count(q) == 1) {
      if (mp.count(w) == 0)
        mp[w] = mp[q];
      else
        mp[w] += mp[q];
      sum -= mp[q] * q;
      sum += mp[q] * w;
      mp.erase(q);
    }
    cout << sum << "\n";
  }
  return 0;
}
