#include <bits/stdc++.h>
const long long MOD = 1e9 + 7;
const long long N = 1e3 + 5;
const long long demo = 10;
using namespace std;
const long long cfmod = 998244353;
long long gcd(long long a, long long b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
long long dx[4] = {0, 0, -1, 1};
long long dy[4] = {-1, 1, 0, 0};
char button[4] = {'L', 'R', 'U', 'D'};
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long q = 1;
  while (q--) {
    long long n;
    cin >> n;
    map<long long, long long> mp;
    long long sum = 0;
    for (long long i = 0; i < n; i++) {
      long long x;
      cin >> x;
      sum += x;
      mp[x]++;
    }
    long long t;
    cin >> t;
    while (t--) {
      long long x, y;
      cin >> x >> y;
      long long left = mp[x];
      sum -= left * x;
      sum += left * y;
      mp[y] += left;
      cout << sum << "\n";
    }
  }
}
