#include <bits/stdc++.h>
using namespace std;
inline bool checkBit(long long n, int i) { return n & (1LL << i); }
inline long long setBit(long long n, int i) {
  return n | (1LL << i);
  ;
}
inline long long resetBit(long long n, int i) { return n & (~(1LL << i)); }
string makeintString(int x) {
  stringstream ss;
  ss << x;
  string str = ss.str();
  return str;
}
string makellString(long long x) {
  stringstream ss;
  ss << x;
  string str = ss.str();
  return str;
}
char cpp(char c) { return static_cast<char>(c + 1); }
const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const long long infLL = 9000000000000000000;
int cnt[2000005];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int t;
  t = 1;
  while (t--) {
    int n, x;
    long long int sum = 0;
    cin >> n;
    for (int i = 0; i < n; i++) {
      cin >> x;
      cnt[x]++;
      sum += x;
    }
    int q;
    cin >> q;
    int b, c;
    for (int i = 0; i < q; i++) {
      cin >> b >> c;
      int minusKoro = b * cnt[b];
      int plusKoro = c * cnt[b];
      cnt[c] += cnt[b];
      cnt[b] = 0;
      sum -= minusKoro;
      sum += plusKoro;
      cout << sum << '\n';
    }
  }
  return 0;
}
