#include <bits/stdc++.h>
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
constexpr int INF = INT_MAX / 2;
constexpr long long LINF = LLONG_MAX / 2;
constexpr double eps = DBL_EPSILON;
constexpr double PI = 3.141592653589793238462643383279;
long long esp_new;
template <class T>
class prique : public std::priority_queue<T, std::vector<T>, std::greater<T>> {
};
template <class T, class U>
inline bool chmax(T& lhs, const U& rhs) {
  if (lhs < rhs) {
    lhs = rhs;
    return 1;
  }
  return 0;
}
template <class T, class U>
inline bool chmin(T& lhs, const U& rhs) {
  if (lhs > rhs) {
    lhs = rhs;
    return 1;
  }
  return 0;
}
inline long long gcd(long long a, long long b) {
  while (b) {
    long long c = a;
    a = b;
    b = c % b;
  }
  return a;
}
inline long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
bool isprime(long long n) {
  if (n == 1) return false;
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0) return false;
  }
  return true;
}
template <typename T>
T mypow(T a, unsigned int b) {
  if (!b) return T(1);
  if (b & 1) return mypow(a, b - 1) * a;
  T memo = mypow(a, b >> 1);
  return memo * memo;
}
long long modpow(long long a, long long b, long long m) {
  if (!b) return 1;
  if (b & 1) return modpow(a, b - 1, m) * a % m;
  long long memo = modpow(a, b >> 1, m);
  return memo * memo % m;
}
template <typename T>
void printArray(std::vector<T>& vec) {
  for (int i = 0; i < (long long)(vec.size() - 1); i++)
    std::cout << vec[i] << " ";
  std::cout << vec.back() << std::endl;
}
template <typename T>
void printArray(T l, T r) {
  T rprev = r;
  rprev--;
  for (T i = l; i != rprev; i++) {
    std::cout << *i << " ";
  }
  std::cout << *rprev << std::endl;
}
int n, q, a[100010];
std::map<int, int> mp;
int main() {
  std::cin >> n;
  long long sum = 0;
  for (int i = 0; i < (long long)(n); i++) {
    std::cin >> a[i];
    mp[a[i]]++;
    sum += a[i];
  }
  std::cin >> q;
  for (int i = 0; i < (long long)(q); i++) {
    int b, c;
    std::cin >> b >> c;
    sum -= b * mp[b];
    sum += c * mp[b];
    mp[c] += mp[b];
    mp[b] = 0;
    std::cout << sum << std::endl;
  }
  return 0;
}
