#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T>
using vec = vector<T>;
const int MOD = 1000000007;
int main() {
  int N;
  cin >> N;
  int A = 0;
  int count[100000 + 2] = {};
  int sum = 0;
  for (int i = 0; i < N; i++) {
    cin >> A;
    count[A]++;
    sum += A;
  }
  int Q;
  cin >> Q;
  vec<int> Ans;
  for (int i = 0; i < Q; i++) {
    int b, c;
    cin >> b >> c;
    sum += (c - b) * count[b];
    count[c] += count[b];
    count[b] = 0;
    Ans.push_back(sum);
  }
  for (int q = 0; q < Q; q++) {
    cout << Ans[q] << endl;
  }
  return 0;
}
