#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
  if (a % b == 0) {
    return (b);
  } else {
    return (gcd(b, a % b));
  }
}
int mod = 1000000000 + 7;
vector<int> v;
class Calc {
  long long a;

 public:
  void decompositPrime(long long a);
};
void Calc::decompositPrime(long long n) {
  a = 2;
  while (n >= a * a) {
    if (n % a == 0) {
      v.push_back(a);
      n /= a;
    } else {
      a++;
    }
  }
  v.push_back(n);
}
vector<int> divisor(int n) {
  vector<int> ret;
  for (int i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  std::sort(ret.begin(), ret.end());
  return ret;
}
long nc2(long n) { return n * (n - 1) / 2; }
template <typename TypeInt>
std::string Itoa(const TypeInt v, int base) {
  static const char table[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  string ret;
  static numeric_limits<TypeInt> t;
  TypeInt n = v;
  if (t.is_signed) {
    if (v < 0) n *= -1;
  }
  while (n >= base) {
    ret += table[n % base];
    n /= base;
  }
  ret += table[n];
  if (t.is_signed) {
    if (v < 0 && base == 10) ret += '-';
  }
  std::reverse(ret.begin(), ret.end());
  return ret;
}
int main() {
  int n, q;
  cin >> n;
  vector<int> a(n);
  vector<int> cnt(100001, 0);
  long sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
    cnt[a[i]]++;
  }
  cin >> q;
  vector<int> b(n);
  vector<int> c(n);
  for (int i = 0; i < q; i++) {
    cin >> b[i] >> c[i];
  }
  for (int i = 0; i < q; i++) {
    sum += c[i] * cnt[b[i]] - b[i] * cnt[b[i]];
    cnt[c[i]] += cnt[b[i]];
    cnt[b[i]] = 0;
    cout << sum << endl;
  }
  return 0;
}
