#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
long long gcd(long long a, long long b, long long temp) {
  if (temp == 1) {
    return 1;
  } else if (a % temp == 0 && b % temp == 0) {
    return temp;
  }
  temp -= max(a % temp, b % temp);
  return gcd(a, b, temp);
}
void fun() {
  long long n;
  cin >> n;
  long long *arr = new long long[n];
  long long sum = 0;
  long long val[100005];
  for (long long i = 0; i <= n - 1; i++) {
    cin >> arr[i];
    sum += arr[i];
    val[arr[i]]++;
  }
  long long q;
  cin >> q;
  while (q--) {
    long long l, k;
    cin >> l >> k;
    sum += (k)*val[l];
    sum -= l * val[l];
    val[k] += val[l];
    val[l] = 0;
    cout << sum << "\n";
  }
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  fun();
  return 0;
}
