#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using ipair = pair<int, int>;
int main() {
  int N, Q, a, b, c, tmp = 0;
  cin >> N;
  vector<int> arr(100001);
  for (int(i) = 0; (i) < (int)(N); (i)++) {
    cin >> a;
    arr[a] += 1;
    tmp += a;
  }
  cin >> Q;
  vector<int> ans(Q + 1, 0);
  ans[0] = tmp;
  for (int(i) = 1; (i) < (int)(Q + 1); (i)++) {
    cin >> b >> c;
    ans[i] = ans[i - 1] - arr[b] * b + arr[b] * c;
    arr[c] = arr[c] + arr[b];
    arr[b] = 0;
  }
  for (int(i) = 1; (i) < (int)(Q + 1); (i)++) cout << ans[i] << endl;
}
