#include <bits/stdc++.h>
using namespace std;
void YES(bool flag) { cout << (flag ? "YES" : "NO") << endl; }
void Yes(bool flag) { cout << (flag ? "Yes" : "No") << endl; }
void yes(bool flag) { cout << (flag ? "yes" : "no") << endl; }
const int INF = 1e7;
const long long MOD = 1e9 + 7;
const double pi = 3.141592653589793;
const vector<int> dx = {1, 0, -1, 0};
const vector<int> dy = {0, 1, 0, -1};
map<int, int> mp;
int main() {
  int n, q;
  long long cnt = 0ll;
  cin >> n;
  for (long long i = 0; i < n; i++) {
    int a;
    cin >> a;
    cnt += a;
    mp[a]++;
  }
  vector<long long> ans;
  cin >> q;
  for (long long i = 0; i < q; i++) {
    int b, c;
    cin >> b >> c;
    cnt = cnt - b * mp[b] + c * mp[b];
    ans.push_back(cnt);
    mp[c] += mp[b];
    mp.erase(b);
  }
  for (long long i = 0; i < ans.size(); i++) cout << ans[i] << endl;
  return 0;
}
