#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, q, ans = 0;
  scanf("%d", &n);
  unordered_map<int, int> mp;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    mp[a[i]]++;
    ans += a[i];
  }
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    int b, c;
    scanf("%d%d", &b, &c);
    mp[c] += mp[b];
    ans += (mp[b] * c - mp[b] * b);
    mp[b] = 0;
    cout << ans;
  }
}
