#include <bits/stdc++.h>
using namespace std;
long long N, M, H, W, Q, K, A, B;
string S;
const long long MOD = 998244353;
const long long INF = (1LL << 58);
int main() {
  cin >> N;
  unordered_map<long long, long long> num;
  long long sum = 0;
  for (int i = 0; i < N; i++) {
    cin >> A;
    ++num[A];
    sum += A;
  }
  cin >> Q;
  for (int _ = 0; _ < Q; _++) {
    cin >> B >> K;
    long long temp = num[B];
    sum -= temp * B;
    sum += temp * K;
    num[K] += temp;
    cout << sum << endl;
  }
}
