#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
ll mod = 1000000007;
ll mod2 = 998244353;
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = (int)(0); i < (int)(n); i++) cin >> a[i];
  int q;
  cin >> q;
  map<int, int> lis;
  ll sum = 0;
  for (int i = (int)(0); i < (int)(n); i++) {
    lis[a[i]]++;
    sum += a[i];
  }
  for (int i = (int)(0); i < (int)(q); i++) {
    int b, c;
    cin >> b >> c;
    if (lis[b]) {
      lis[c] += lis[b];
      sum = sum - b * lis[b] + c * lis[b];
      lis[b] = 0;
    }
    cout << sum << endl;
  }
}
