#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using vec = vector<int>;
using P = pair<int, int>;
const int INF = 1e9 + 7;
int main() {
  int n;
  cin >> n;
  map<int, int> mp;
  ll sum = 0;
  for (int i = 0; i < (n); ++i) {
    int a;
    cin >> a;
    mp[a]++;
    sum += a;
  }
  int q;
  cin >> q;
  for (int i = 0; i < (q); ++i) {
    int b, c;
    cin >> b >> c;
    sum += (c - b) * mp[b];
    mp[c] += mp[b];
    mp[b] = 0;
    printf("%d\n", sum);
  }
}
