#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
const long long INF = 1LL << 60;
int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  for (long long i = 0; i < N; i++) cin >> a[i];
  map<int, int> m;
  long long ans = 0;
  for (long long i = 0; i < N; i++) {
    m[a[i]]++;
    ans += a[i];
  }
  int Q;
  cin >> Q;
  vector<long long> sum;
  for (long long i = 0; i < Q; i++) {
    int B, C;
    cin >> B >> C;
    ans -= m[B] * B;
    ans += m[B] * C;
    m[C] += m[B];
    m[B] = 0;
    sum.push_back(ans);
  }
  for (long long i = 0; i < Q; i++) cout << sum[i] << endl;
}
