#include <bits/stdc++.h>
using namespace std;
const long long int MOD = 1000000007;
const long double PI = 3.1415926535897932384626433832795;
long long int pwr(long long int b, long long int p) {
  long long int res = 1;
  while (p) {
    if (p & 1) {
      res *= b;
      p--;
    } else {
      b *= b;
      p >>= 1;
    }
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  long long int n;
  cin >> n;
  vector<long long int> A(n);
  map<long long int, long long int> mp;
  for (int i = 0; i < n; i += 1) {
    cin >> A[i];
    ++mp[A[i]];
  }
  long long int q;
  cin >> q;
  long long int sum = accumulate(A.begin(), A.end(), 0);
  for (int i = 0; i < q; i += 1) {
    long long int a, b;
    cin >> a >> b;
    sum = sum - mp[a] * a + mp[a] * b;
    mp[b] += mp[a];
    mp.erase(a);
    cout << sum << "\n";
  }
  return 0;
}
