#include <bits/stdc++.h>
using namespace std;
vector<long long int> Ans;
int main() {
  int N, Q, x;
  cin >> N;
  long long int ans = 0;
  vector<int> a(100001, 0);
  for (int i = 0; i < N; i++) {
    cin >> x;
    ans += x;
    a[x]++;
  }
  cin >> Q;
  while (Q--) {
    int b, c;
    cin >> b >> c;
    a[c] += a[b];
    ans = ans - b * a[b] + c * a[b];
    Ans.push_back(ans);
    a[b] = 0;
  }
  for (auto n : Ans) cout << n << endl;
}
