#include <bits/stdc++.h>
using namespace std;
long long MOD(long long x, long long m) {
  long long r = x % m;
  if (r < 0) {
    r += m;
  }
  return r;
}
ostream& operator<<(ostream& str, const pair<long long, long long>& p) {
  str << p.first << " " << p.second;
  return str;
}
template <typename T>
void join(T& arr, string sep) {
  bool first = true;
  for (auto t : arr) {
    if (first) {
      first = false;
      cout << t;
    } else {
      cout << sep << t;
    }
  }
  cout << "\n";
}
void solve() {
  long long n;
  cin >> n;
  vector<long long> a(n);
  long long sum = 0;
  map<long long, long long> mp;
  for (long long i = 0; i < (long long)(n); ++i) {
    cin >> a[i];
    sum += a[i];
    mp[a[i]]++;
  }
  long long q;
  cin >> q;
  for (long long i = 0; i < (long long)(q); ++i) {
    long long b, c;
    cin >> b >> c;
    long long size = mp[b];
    sum -= b * size;
    sum += c * size;
    mp[c] += size;
    cout << sum << "\n";
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int tt = 1;
  for (int t = 1; t <= tt; t++) {
    solve();
  }
  return 0;
}
