#include <bits/stdc++.h>
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD = int(1e9) + 7;
using namespace std;
using pii = pair<int, int>;
long long gcd(long long x, long long y) {
  if (x < y) swap(x, y);
  long long r = x % y;
  while (r != 0) {
    x = y;
    y = r;
    r = x % y;
  }
  return y;
}
long long lcm(long long x, long long y) {
  long long a = x * y;
  return (a / gcd(x, y));
}
signed main(void) {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  map<int, int> ans;
  int a[n + 5];
  long long sum = 0;
  for (int i = 0; i < (n); i++) {
    cin >> a[i];
    ans[a[i]]++;
    sum += a[i];
  }
  int q, b, c;
  cin >> q;
  for (int i = 0; i < (q); i++) {
    cin >> b >> c;
    sum -= b * ans[b];
    sum += ans[b] * c;
    ans[c] += ans[b];
    ans[b] = 0;
    cout << sum << '\n';
  }
  return 0;
}
