#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const double PI = 3.141592653589793238463;
const int MAXN = 20000005;
bool isPrime[MAXN];
vector<int> pr;
vector<pair<int, int>> ans;
void sieve() {
  memset(isPrime, 1, sizeof isPrime);
  isPrime[0] = isPrime[1] = 0;
  for (int i = 2; i * i <= MAXN; i += 1 + (i & 1)) {
    if (isPrime[i]) {
      for (int j = i * i; j < MAXN; j += i) isPrime[j] = 0;
    }
  }
  for (int i = 0; i < MAXN; i++) {
    if (isPrime[i]) {
      if (!pr.empty()) {
        if (i - pr.back() == 2) {
          ans.push_back({pr.back(), i});
        }
      }
      pr.push_back(i);
    }
  }
}
long double power(long double x, long long y) {
  long long temp;
  if (y == 0) return 1;
  temp = power(x, y / 2);
  if (y % 2 == 0)
    return temp * temp;
  else
    return x * temp * temp;
}
void debug_out() { cerr << '\n'; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << H;
  debug_out(T...);
}
int pre[MAXN];
int main() {
  int n;
  cin >> n;
  int arr[n];
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    sum += arr[i];
    pre[arr[i]]++;
  }
  int q;
  cin >> q;
  while (q--) {
    int a, b;
    cin >> a >> b;
    sum -= pre[a] * a;
    sum += pre[a] * b;
    cout << sum << '\n';
    pre[b] += pre[a];
    pre[a] = 0;
  }
  return 0;
}
