#include <bits/stdc++.h>
using namespace std;
int arr[100005];
int arr2[100005];
long long int po(long long int a, long long int b) {
  int res = 1;
  while (b) {
    if (b % 2 != 0) {
      res *= a;
      b--;
    } else {
      a *= a;
      b /= 2;
    }
  }
  return res;
}
long long int modMul(long long int a, long long int b, long long int mod) {
  long long int ans = 0;
  a = a % mod;
  while (b > 0) {
    if (b % 2) ans = (ans % mod + a % mod) % mod;
    a = (a % mod * 2 % mod) % mod;
    b /= 2;
  }
  return ans % mod;
}
long long int powerMod(long long int a, long long int b, long long int mod) {
  if (b == 0) return 1LL % mod;
  long long int x = powerMod(a, b / 2, mod);
  x = (x % mod * x % mod) % mod;
  if (b % 2 == 1) x = (x % mod * a % mod) % mod;
  return x % mod;
}
int main() {
  int n, sum = 0;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &arr[i]);
    ;
    arr2[arr[i]]++;
    sum += arr[i];
  }
  int q;
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    int a, b;
    scanf("%d", &a);
    scanf("%d", &b);
    int p = arr2[a];
    int sum2 = p * a;
    sum -= sum2;
    int sum3 = p * b;
    sum += sum3;
    arr2[a] -= p;
    arr2[b] += p;
    printf("%d\n", sum);
  }
}
