#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N, Q;
  long long buf;
  long long inp1, inp2;
  long long sum = 0;
  cin >> N;
  vector<long long> ans(N);
  vector<long long> num(100001);
  for (int i = 0; i < N; i++) {
    cin >> buf;
    num.at(buf)++;
    sum += buf;
  }
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    cin >> inp1 >> inp2;
    sum = sum + (inp2 - inp1) * num.at(inp2);
    num.at(inp2) += num.at(inp1);
    num.at(inp1) = 0;
    cout << sum << endl;
  }
}
