#include <bits/stdc++.h>
using namespace std;
long long Ceil(long long a, long long b) {
  if (a % b == 0)
    return a / b;
  else
    return a / b + 1;
}
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long inv(long long a) {
  long long p = 1000000007;
  long long b = p - 2, ans = 1;
  for (; b > 0; a = a * a % p, b >>= 1)
    if (b & 1) ans = ans * a % p;
  return ans;
}
long long ncrmod(long long n, long long m) {
  long long p = 1000000007;
  if (m > n) return 0;
  long long up = 1, down = 1;
  for (long long i = n - m + 1; i < n + 1; i++) up *= i, up %= p;
  for (long long i = 1; i < m + 1; i++) down *= i, down %= p;
  return up * inv(down) % p;
}
long long powmod(long long a, long long n) {
  if (!n) return 1;
  long long pt = powmod(a, n / 2);
  pt *= pt, pt %= 1000000007;
  if (n & 1) pt *= a, pt %= 1000000007;
  return pt;
}
void solve() {
  long long n;
  cin >> n;
  long long a[n];
  for (long long i = 0; i < n; i++) cin >> a[i];
  long long freq[100005];
  memset(freq, 0, sizeof(freq));
  ;
  long long sum = 0;
  for (long long i = 0; i < n; i++) {
    sum += a[i];
    freq[a[i]]++;
  }
  long long k;
  cin >> k;
  while (k--) {
    long long b, c;
    cin >> b >> c;
    freq[c] += freq[b];
    sum = sum - b * freq[b] + c * freq[c];
    freq[b] = 0;
    cout << sum << "\n";
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  long long t;
  t = 1;
  while (t--) {
    solve();
  }
  cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
  return 0;
}
