#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> count(10001);
  long long sum = 0;
  for (long long i = 0; i < (n); i++) {
    cin >> a.at(i);
    sum += a.at(i);
    count.at(a.at(i))++;
  }
  int q;
  cin >> q;
  for (long long i = 0; i < (q); i++) {
    int a, b;
    cin >> a >> b;
    sum = sum + (b - a) * count.at(a);
    count.at(b) += count.at(a);
    count.at(a) = 0;
    cout << sum << endl;
  }
  return 0;
}
