#include <bits/stdc++.h>
using namespace std;
long long int min(long long int a, long long int b) { return (a < b) ? a : b; }
long long int max(long long int a, long long int b) { return (a > b) ? a : b; }
long long int fp(long long int a, long long int b) {
  if (b == 0) return 1;
  long long int x = fp(a, b / 2);
  x = (x * x) % 1000000007;
  if (b & 1) x = (x * a) % 1000000007;
  return x;
}
long long int factorial(long long int n) {
  long long int fact = 1;
  for (long long int i = 2; i <= n; i++) fact = fact * i;
  return fact;
}
long long int ncr(long long int n, long long int r) {
  return factorial(n) / (factorial(r) * factorial(n - r));
}
void c_p_c() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
}
signed main() {
  c_p_c();
  long long int n;
  cin >> n;
  long long int a[n + 1];
  unordered_map<long long int, long long int> m;
  for (long long int i = 1; i <= n; i++) {
    cin >> a[i];
    m[a[i]]++;
  }
  long long int sum = accumulate(a + 1, a + 1 + n, 0);
  long long int q;
  cin >> q;
  while (q--) {
    long long int b, c;
    cin >> b >> c;
    long long int freq = m[b];
    sum = sum - (freq * b) + (freq * c);
    m[c] += m[b];
    m[b] = 0;
    cout << sum << "\n";
  }
}
