#include <bits/stdc++.h>
using namespace std;
long long power(long long a, long long b) {
  long long res = 1;
  while (b > 0) {
    if (b & 1) res = res * a;
    a = a * a;
    b >>= 1;
  }
  return res;
}
long long int binomial(long long int n, long long int k) {
  long long int C[k + 1];
  memset(C, 0, sizeof(C));
  C[0] = 1;
  for (long long int i = 1; i <= n; i++) {
    for (int j = min(i, k); j > 0; j--) C[j] = C[j] + C[j - 1];
  }
  return C[k];
}
vector<int> pr;
void Sieve(long long int n) {
  bool prime[10000000];
  memset(prime, true, sizeof(prime));
  for (int p = 2; p * p <= n; p++) {
    if (prime[p] == true) {
      pr.push_back(p);
      for (int i = p * p; i <= n; i += p) prime[i] = false;
    }
  }
}
pair<int, int> fib(int n) {
  if (n == 0) return {0, 1};
  auto p = fib(n >> 1);
  int c = p.first * (2 * p.second - p.first);
  int d = p.first * p.first + p.second * p.second;
  if (n & 1)
    return {d, c + d};
  else
    return {c, d};
}
int main() {
  long long int n;
  cin >> n;
  long long int a[n];
  map<int, int> mp;
  long long int s = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    s += a[i];
    mp[a[i]]++;
  }
  long long int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int b, c;
    cin >> b >> c;
    if (mp.find(b) != mp.end()) {
      s -= mp[b] * b;
      s += mp[b] * c;
      cout << s << endl;
      mp[c] += mp[b];
      mp[b] = 0;
    } else {
      cout << s << endl;
    }
  }
}
