#include <bits/stdc++.h>
using namespace std;
int max(int a, int b) {
  if (a > b) return a;
  return b;
}
bool isPrime(long long a) {
  if (a <= 1) return false;
  if (a <= 3) return true;
  if (a % 2 == 0 || a % 3 == 0) return false;
  for (long long i = 5; i * i <= a; i = i + 6) {
    if (a % i == 0 || a % (i + 2) == 0) return false;
  }
  return true;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  int sum = 0;
  vector<int> cou(100001, 0);
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
    cou[a[i]]++;
  }
  int q;
  cin >> q;
  for (long long i = 0; i < q; i++) {
    int b, c;
    cin >> b >> c;
    cou[c] += cou[b];
    sum = sum - cou[b] * b + cou[b] * c;
    cou[b] = 0;
    cout << sum << '\n';
  }
  return 0;
}
