#include <bits/stdc++.h>
using namespace std;
bool isPrime(int n) {
  if (n <= 1) return false;
  if (n <= 3) return true;
  if (n % 2 == 0 || n % 3 == 0) return false;
  for (int i = 5; i * i <= n; i = i + 6)
    if (n % i == 0 || n % (i + 2) == 0) return false;
  return true;
}
long long int powe(long long int x, long long int y) {
  long long int res = 1;
  while (y > 0) {
    if (y & 1) res = res * x;
    y = y >> 1;
    x = x * x;
  }
  return res;
}
void solve() {
  long long int i, j, k = 0, n, l;
  cin >> n;
  vector<long long int> v(n);
  map<long long int, long long int> m;
  long long int sum = 0;
  for (i = 0; i < n; i++) {
    cin >> v[i];
    sum += v[i];
    m[v[i]]++;
  }
  long long int q;
  cin >> q;
  long long int x, y;
  while (q--) {
    cin >> x >> y;
    k = m[x];
    sum -= k * x;
    m[y] += k;
    sum += k * y;
    cout << sum << endl;
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long int i, j, l, k, t, n;
  t = 1;
  while (t--) solve();
}
