#include <bits/stdc++.h>
using namespace std;
long long int ipow(long long int x, long long int n) {
  long long int result = 1;
  while (n) {
    if (n & 1) result = result * x % 1000000007;
    n = n / 2;
    x = x * x % 1000000007;
  }
  return result;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int n;
  cin >> n;
  unordered_map<long long int, long long int> m;
  long long int a[n];
  for (long long int i = 0; i < n; i++) {
    cin >> a[i];
    m[a[i]]++;
  }
  long long int s = 0;
  for (long long int i = 0; i < n; i++) s += a[i];
  long long int t;
  cin >> t;
  while (t--) {
    long long int x, y;
    cin >> x >> y;
    s = s - x * m[x] + y * m[x];
    long long int t = m[x];
    while (t--) {
      m[x] -= m[x];
      m[y]++;
    }
    cout << s << "\n";
  }
  return 0;
}
