#include <bits/stdc++.h>
using namespace std;
bool IsPrime(long long num) {
  if (num < 2)
    return false;
  else if (num == 2)
    return true;
  else if (num % 2 == 0)
    return false;
  double sqrtNum = sqrt(num);
  for (long long i = 3; i <= sqrtNum; i += 2) {
    if (num % i == 0) {
      return false;
    }
  }
  return true;
}
int main() {
  long long n;
  cin >> n;
  vector<long long> a(n);
  map<long long, long long> m;
  for (long long i = 0; i < (long long)(n); i++) {
    cin >> a[i];
    m[a[i]]++;
  }
  long long q;
  cin >> q;
  vector<long long> b(q), c(q);
  long long sum = 0;
  for (const auto& [key, value] : m) {
    sum += key * value;
  }
  for (long long i = 0; i < (long long)(q); i++) {
    cin >> b[i] >> c[i];
    long long diff = c[i] - b[i];
    sum += diff * m[b[i]];
    m[c[i]] += m[b[i]];
    m[b[i]] = 0;
    pair<long long, long long> item;
    for (auto it = m.begin(); it != m.end(); it++) {
      item = *it;
    }
    cout << sum << endl;
  }
  return 0;
}
