#include <bits/stdc++.h>
using namespace std;
const long long MAX = 510000;
const long long INF = 1LL << 60;
const long long MOD = 998244353;
template <class T>
inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  map<int, int> m;
  long long sum = 0;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    m[a[i]]++;
    sum += a[i];
  }
  int q;
  cin >> q;
  for (long long i = 0; i < q; i++) {
    int b, c;
    cin >> b >> c;
    cout << sum + (c - b) * m[b] << endl;
    sum = sum + (c - b) * m[b];
    m[c] = m[b];
    m[b] = 0;
  }
}
