#include <bits/stdc++.h>
long long int power(long long int x, long long int b) {
  long long int p = 1;
  while (b > 0) {
    if (b & 1) {
      p = p * x;
      p %= 9000000000000000000;
    }
    b >>= 1;
    x *= x;
    x %= 9000000000000000000;
  }
  return p % 9000000000000000000;
}
using namespace std;
struct lex_compare {
  bool operator()(const pair<long double, long long int> p1,
                  const pair<long double, long long int> p2) {
    return (p1.first == p2.first) ? p1.second < p2.second : p1.first > p2.first;
  }
};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  long long int n;
  cin >> n;
  map<long long int, long long int> m;
  long long int sum = 0;
  for (long long int i = 0; i < n; i++) {
    long long int a;
    cin >> a;
    m[a]++;
    sum += a;
  }
  long long int q;
  cin >> q;
  while (q--) {
    long long int b, c;
    cin >> b >> c;
    long long int countb = m[b];
    m[c] += m[b];
    sum += ((c - b) * countb);
    cout << sum << "\n";
  }
  return 0;
}
