#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int gcd(int a, int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
int power(int x, int y, int p) {
  int res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
int modInverse(int n, int p) { return power(n, p - 2, p); }
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> v(n);
  map<int, int> mp;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    mp[x]++;
  }
  ll s = 0;
  for (auto x : mp) {
    s += (x.first * x.second);
  }
  int q;
  cin >> q;
  while (q-- > 0) {
    int b, val;
    cin >> b >> val;
    if (mp.count(b)) {
      s = s - b * mp[b];
      s = s + val * mp[b];
      mp[val] += mp[b];
      mp.erase(b);
    }
    cout << s << '\n';
  }
}
