#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
long long ketasu(long long a) {
  long long num = 1;
  while (a / 10) {
    num++;
    a /= 10;
  }
  return num;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return a * b / gcd(a, b); }
long long kosuu(long long a) {
  long long sum = 0;
  for (long long i = 1; i * i <= a; i++) {
    if (a % i == 0) {
      if (a != 1 && i * i != a) {
        sum += 2;
      } else {
        sum++;
      }
    }
  }
  return sum;
}
int main() {
  long long n;
  cin >> n;
  map<long long, long long> mp;
  long long a;
  for (long long i = 0; i < n; i++) {
    cin >> a;
    mp[a]++;
  }
  long long q;
  cin >> q;
  long long b;
  for (long long i = 0; i < q; i++) {
    cin >> a >> b;
    mp[b] += mp[a];
    mp[a] = 0;
    long long sum = 0;
    for (auto m : mp) {
      sum += m.first * m.second;
    }
    cout << sum << endl;
  }
}
