#include <bits/stdc++.h>
using namespace std;
typedef vector<pair<long long int, long long int>> vec_p;
const long long int MOD = pow(10, 9) + 7;
const long long int LLINF = pow(2, 61) - 1;
const int INF = pow(2, 30) - 1;
long long int gcd(long long int a, long long int b) {
  return b ? gcd(b, a % b) : a;
}
vector<long long int> p(10000 + 10);
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long int N;
  string S;
  cin >> N;
  vector<long long int> A(N);
  for (long long int i = 0; i < (long long int)(N); i++) {
    cin >> A.at(i);
  }
  long long int Q;
  cin >> Q;
  vector<long long int> B(Q), C(Q);
  for (long long int i = 0; i < (long long int)(Q); i++) {
    cin >> B.at(i) >> C.at(i);
  }
  for (long long int i = 0; i < (long long int)(N); i++) {
    p.at(A.at(i))++;
  }
  long long int ans = 0;
  for (long long int i = 0; i < (long long int)(N); i++) {
    ans += A.at(i);
  }
  for (long long int i = 0; i < (long long int)(Q); i++) {
    long long int tmp = p.at(B.at(i));
    p.at(C.at(i)) += tmp;
    long long int tmp1 = (C.at(i) - B.at(i)) * tmp;
    ans += tmp1;
    cout << ans << endl;
    p.at(B.at(i)) = 0;
  }
}
