#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
const long long MOD = 1e9 + 7;
const long long N = 2005;
const long long maxN = 1e5 + 5;
const long long MAX_SIZE = 1e8 + 8;
long long power(long long x, long long y, long long M = MOD) {
  long long v = 1;
  x = x % M;
  while (y > 0) {
    if (y & 1) v = (v * x) % M;
    y = y >> 1;
    x = (x * x) % M;
  }
  return v;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n;
  cin >> n;
  map<long long, long long> ar;
  long long sum = 0;
  for (long long i = 0; i < n; i++) {
    long long x;
    cin >> x;
    ar[x]++;
    sum += x;
  }
  long long q;
  cin >> q;
  while (q--) {
    long long b, c;
    cin >> b >> c;
    long long kk = ar[b];
    if (kk == 0)
      cout << sum << "\n";
    else {
      sum -= (kk * b);
      sum += (kk * c);
      cout << sum << "\n";
      ar.erase(b);
      ar[c] = kk;
    }
  }
  return 0;
}
