#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
const long long INF = 1LL << 60;
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int ctoi(char c) {
  switch (c) {
    case '0':
      return 0;
    case '1':
      return 1;
    case '2':
      return 2;
    case '3':
      return 3;
    case '4':
      return 4;
    case '5':
      return 5;
    case '6':
      return 6;
    case '7':
      return 7;
    case '8':
      return 8;
    case '9':
      return 9;
    default:
      return 0;
  }
}
bool is_prime(const unsigned n) {
  switch (n) {
    case 0:
    case 1:
      return false;
    case 2:
    case 3:
      return true;
  }
  if (n % 2 == 0 || n % 3 == 0) return false;
  for (unsigned i = 5; i * i <= n; i += 6) {
    if (n % i == 0) return false;
    if (n % (i + 2) == 0) return false;
  }
  return true;
}
map<int, int> mp;
int primeFactorization(int a) {
  int i, sq;
  if (a % 2 == 0) {
    if (!mp.count(2)) {
      mp[2] = 1;
    } else {
      mp[2] += 1;
    }
    return primeFactorization(a / 2);
  }
  sq = sqrt(a);
  for (i = 3; i <= sq; i += 2) {
    if (a % i == 0) {
      if (!mp.count(i)) {
        mp[i] = 1;
      } else {
        mp[i] += 1;
      }
      return primeFactorization(a / i);
    }
  }
  if (a != 1) {
    if (!mp.count(a))
      mp[a] = 1;
    else {
      mp[a] += 1;
    }
  }
  return 0;
}
long long kaizyou(long long n) {
  if (n == 1) {
    return 1;
  } else {
    return (n * kaizyou(n - 1)) % 1000000007;
  }
}
int main() {
  long long N;
  cin >> N;
  map<long long, long long> m;
  vector<long long> A(N + 1);
  long long sum = 0;
  for (int i = 0; i < (int)(N); i++) {
    cin >> A[i];
    sum += A[i];
    if (!m.count(A[i]))
      m[A[i]] = 1;
    else
      m[A[i]] += 1;
  }
  long long Q;
  cin >> Q;
  vector<long long> ans(N);
  for (int i = 0; i < (int)(Q); i++) {
    long long b, c;
    cin >> b >> c;
    if (!m.count(b)) m[b] = 0;
    sum -= m[b] * b;
    sum += c * m[b];
    if (!m.count(c))
      m[c] = m[b];
    else
      m[c] += m[b];
    m[b] = 0;
    ans[i] = sum;
  }
  for (int i = 0; i < (int)(Q); i++) cout << ans[i] << endl;
}
