#include <bits/stdc++.h>
using namespace std;
long long power(long long a, long long b) {
  long long res = 1;
  a = a % 1000000007;
  while (b) {
    if (b & 1) res = (res * a) % 1000000007;
    a = (a * a) % 1000000007;
    b /= 2;
  }
  return res;
}
long long invmod(long long a) { return power(a, 1000000007 - 2); }
int main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, x, q, y;
  cin >> n;
  int arr[100002] = {0};
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    cin >> x;
    arr[x]++;
    ans += x;
  }
  cin >> q;
  while (q--) {
    cin >> x >> y;
    ans += y * arr[x];
    arr[y] += arr[x];
    ans -= arr[x] * x;
    arr[x] = 0;
    cout << ans << '\n';
  }
  return 0;
}
