#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1);
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 / gcd(a, b) * b; }
int main() {
  int n;
  cin >> n;
  map<int, int> mp;
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    int A;
    cin >> A;
    mp[A]++;
    sum += A;
  }
  int q;
  cin >> q;
  vector<pair<int, int>> vec(q);
  for (int i = 0; i < q; i++) {
    int b, c;
    cin >> b >> c;
    vec[i].first = b;
    vec[i].second = c;
  }
  for (int i = 0; i < q; i++) {
    int b, c;
    b = vec[i].first;
    c = vec[i].second;
    if (mp[b] == 0 || b == c) {
      cout << sum << endl;
    } else {
      sum -= mp[b] * b;
      sum += mp[b] * c;
      mp[c] += mp[b];
      mp[b] = 0;
      cout << sum << endl;
    }
  }
}
