#include <bits/stdc++.h>
using namespace std;
long long int mod = 1e9 + 7;
vector<long long int> DecToBinary(long long int num,
                                  long long int trailing_zero,
                                  long long int nbits) {
  vector<long long int> bits;
  while (num > 0) {
    bits.push_back(num % 2);
    num /= 2;
  }
  if (trailing_zero == 1) {
    while (bits.size() < nbits) {
      bits.push_back(0);
    }
  }
  return bits;
}
long long int BinaryToDec(vector<long long int> bits) {
  long long int number = 0;
  long long int i;
  for (i = bits.size() - 1; i >= 0; i--) {
    number += (bits[i] * (long long)pow((long long int)2, i));
  }
  return number;
}
long long int modular_exponentiation(long long int base, long long int power) {
  long long int ans = 1;
  base = base % mod;
  while (power > 0) {
    if (power & 1) {
      ans = (ans * base) % mod;
    }
    power /= 2;
    base = (base * base) % mod;
  }
  return ans;
}
int main() {
  long long int t = 1;
  while (t--) {
    long long int n, i, j;
    cin >> n;
    long long int arr[n];
    long long int sum = 0;
    unordered_map<long long int, long long int> mp;
    for (i = 0; i < n; i++) {
      cin >> arr[i];
      sum += arr[i];
      auto it = mp.find(arr[i]);
      if (it == mp.end()) {
        mp[arr[i]] = 1;
      } else {
        mp[arr[i]]++;
      }
    }
    long long int q;
    cin >> q;
    for (i = 0; i < q; i++) {
      long long int a, b;
      cin >> a >> b;
      auto it = mp.find(a);
      if (it != mp.end()) {
        long long int times = it->second;
        sum -= (a * times);
        sum += (b * times);
        auto it2 = mp.find(b);
        if (it2 == mp.end()) {
          mp[b] = times;
        } else {
          mp[b] += times;
        }
      }
      cout << sum << '\n';
    }
  }
  return 0;
}
