#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
long long powmod(long long a, long long b) {
  long long res = 1;
  a %= mod;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
const int maxx = 1e7 + 10;
int num[maxx];
long long sum = 0, tsum;
int main() {
  int n;
  memset(num, 0, sizeof(num));
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int a;
    scanf("%d", &a);
    num[a]++;
    sum += a;
  }
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    if (num[a] == 0) {
      printf("%lld\n", sum);
      continue;
    }
    int t = num[a];
    num[a] = 0;
    num[b] += t;
    sum -= a * t;
    sum += b * t;
    printf("%lld\n", sum);
  }
}
