#include <bits/stdc++.h>
using namespace std;
long long gcd(long long n, long long m) { return m ? gcd(m, n % m) : n; }
long long lcm(long long n, long long m) { return n / gcd(n, m) * m; }
struct debugger {
  static void call(string::iterator it, string::iterator ed) {}
  template <typename T, typename... aT>
  static void call(string::iterator it, string::iterator ed, T a, aT... rest) {
    string b;
    for (; *it != ','; ++it)
      if (*it != ' ') b += *it;
    cout << b << "=" << a << " ";
    call(++it, ed, rest...);
  }
};
vector<long long> arr(100005);
void solve() {
  int n;
  cin >> n;
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    int k;
    cin >> k;
    sum += k;
    arr[k]++;
  }
  int test;
  cin >> test;
  while (test--) {
    int a, b;
    cin >> a >> b;
    sum -= arr[a] * a;
    sum += arr[a] * b;
    arr[b] = arr[a];
    arr[a] = 0;
    cout << sum << '\n';
  }
}
int main() { solve(); }
