#include <bits/stdc++.h>
using namespace std;
const int Maxn = 1e6 + 1;
const int Mod = 1e9 + 7;
const long long int MOD = 1000000007LL;
const long long int MAX = 100010LL;
template <typename T>
T gcd(T a, T b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
template <typename T>
T power(T x, T y, long long int m = MOD) {
  T ans = 1;
  x %= m;
  while (y > 0) {
    if (y & 1ll) ans = (ans * x) % m;
    y >>= 1ll;
    x = (x * x) % m;
  }
  return ans % m;
}
template <typename T, typename T1>
T mod(T x, T1 p) {
  x %= p;
  if (x < 0) x += p;
  return x;
}
void leastPrimeFactor(vector<int>& least_prime, int n) {
  least_prime[1] = 1;
  for (int i = 2; i <= n; i++) {
    if (least_prime[i] == 0) {
      least_prime[i] = i;
      for (int j = 2 * i; j <= n; j += i)
        if (least_prime[j] == 0) least_prime[j] = i;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  map<int, int> make_pair;
  long long int sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
    if (make_pair.find(a[i]) == make_pair.end())
      make_pair[a[i]] = 1;
    else
      make_pair[a[i]]++;
  }
  int q, b, c;
  cin >> q;
  while (q--) {
    cin >> b >> c;
    if (make_pair.find(b) != make_pair.end()) {
      sum -= (make_pair[b] * b);
      sum += (make_pair[b] * c);
      if (make_pair.find(c) == make_pair.end())
        make_pair[c] = make_pair[b];
      else
        make_pair[c] += make_pair[b];
      make_pair.erase(make_pair.find(b));
    }
    cout << sum << endl;
  }
}
