#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const long double Pi = acos(-1);
using P = pair<long long, long long>;
long long gcd(long long a, long long b) {
  if (a % b == 0) {
    return b;
  } else {
    return gcd(b, a % b);
  }
}
long long lcm(long long a, long long b) { return a * b / gcd(a, b); }
long long pow(long long x, long long y) {
  long long tmp = x, res = 1;
  while (y) {
    if (y % 2) {
      res = res * tmp % MOD;
    }
    y >>= 1;
    tmp = tmp * tmp % MOD;
  }
  return res;
}
long long nature(long long a) {
  if (a >= 0) {
    return (a);
  } else {
    return (-1 * a);
  }
}
long long prime(long long a) {
  if (a == 2) {
    return 1;
  } else if (a % 2 == 0 || a == 1) {
    return 0;
  }
  for (long long i = 3; i * i <= a; i += 2) {
    if (a % i == 0) {
      return 0;
    }
  }
  return 1;
}
int main() {
  int N, sum = 0;
  cin >> N;
  vector<int> A(N);
  unordered_map<int, int> mp;
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
    mp[A.at(i)]++;
    sum += A.at(i);
  }
  int Q;
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    int a, b;
    cin >> a >> b;
    mp[b] += mp[a];
    sum -= a * mp[a];
    sum += b * mp[a];
    mp[a] = 0;
    cout << sum << endl;
  }
}
