#include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 60;
int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long Array[100000] = {0};
  long long N;
  long long sum = 0;
  cin >> N;
  for (long long i = 0; i < (long long)N; i++) {
    long A;
    cin >> A;
    sum += A;
    Array[A]++;
  }
  long long Q;
  cin >> Q;
  vector<long long> ans;
  for (long long i = 0; i < (long long)Q; i++) {
    long long B, C;
    cin >> B >> C;
    long long diff = C - B;
    sum += Array[B] * diff;
    ans.push_back(sum);
    Array[C] += Array[B];
    Array[B] = 0;
  }
  for (auto x : ans) {
    cout << x << endl;
  }
EndPoint:;
  system("pause");
  return 0;
}
