#include <bits/stdc++.h>
using namespace std;
int on_bit(int N, int pos) { return N = N | (1 << pos); }
int off_bit(int N, int pos) { return N = N & ~(1 << pos); }
bool check_bit(long long int N, int pos) { return (bool)(N & (1 << pos)); }
template <class T>
inline bool read(T &x) {
  int c = getchar();
  int sgn = 1;
  while (~c && c < '0' || c > '9') {
    if (c == '-') sgn = -1;
    c = getchar();
  }
  for (x = 0; ~c && '0' <= c && c <= '9'; c = getchar()) x = x * 10 + c - '0';
  x *= sgn;
  return ~c;
}
inline long long int exp(long long int a, long long int p) {
  if (p == 0) return 1;
  long long int x = exp(a, p / 2) % 1000000007;
  x = (x * x) % 1000000007;
  if (p & 1) x = (x * (a % 1000000007)) % 1000000007;
  return x;
}
inline int add(int a, int b) {
  a += b;
  if (a >= 1000000007) a -= 1000000007;
  return a;
}
inline int sub(int a, int b) {
  a -= b;
  if (a < 1000000007) a += 1000000007;
  return a;
}
inline int multi(long long int a, long long int b) {
  a *= b;
  if (a >= 1000000007) a %= 1000000007;
  return a;
}
int main() {
  int n;
  cin >> n;
  vector<int> v(n);
  map<int, int> mp;
  for (int i = 0; i < n; i++) {
    cin >> v[i];
    mp[v[i]]++;
  }
  long long int sum = accumulate(v.begin(), v.end(), 0);
  int q;
  cin >> q;
  while (q--) {
    int x, y;
    cin >> x >> y;
    sum -= mp[x] * x;
    sum += mp[x] * y;
    mp[y] += mp[x];
    mp.erase(x);
    cout << sum << "\n";
  }
  return 0;
}
