#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  std::vector<int> v(n + 1);
  for (int i = 1; i <= n; ++i) {
    cin >> v[i];
  }
  int initSum = 0;
  for (int i = 1; i <= n; ++i) {
    initSum = initSum + v[i];
  }
  unordered_map<int, int> mp;
  for (int i = 1; i <= n; ++i) {
    mp[v[i]]++;
  }
  int q;
  cin >> q;
  for (int k = 1; k <= q; ++k) {
    int b, c;
    cin >> b >> c;
    if (mp[b] != 0) {
      int sum = initSum - mp[b] * b + mp[b] * c;
      mp[c] = mp[c] + mp[b];
      mp[b] = 0;
      initSum = sum;
    }
    cout << initSum << endl;
  }
}
