#include <bits/stdc++.h>
using namespace std;
long long gcdEx(long long a, long long b, long long* x, long long* y) {
  if (!a) {
    *x = 0;
    *y = 1;
    return b;
  }
  long long x1, y1, gcd = gcdEx(b % a, a, &x1, &y1);
  *x = y1 - (b / a) * x1;
  *y = x1;
  return gcd;
}
long long modI(long long b, long long m) {
  long long x, y;
  gcdEx(b, m, &x, &y);
  return (x % m + m) % m;
}
long long modP(long long x, long long y) {
  long long r = 1;
  x %= 1000000007;
  while (y > 0) {
    if (y & 1) {
      r = (r * x) % 1000000007;
    }
    y = y >> 1;
    x = (x * x) % 1000000007;
  }
  return r;
}
long long max(long long a, long long b) { return (a > b ? a : b); }
long long min(long long a, long long b) { return (a < b ? a : b); }
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " = " << arg1 << " | ";
  __f(comma + 1, args...);
}
long long gcd(long long a, long long b) {
  if (b == 0) {
    return a;
  } else {
    return gcd(b, (a % b));
  }
}
long long lcm(long long a, long long b) {
  long long ans = (a / gcd(a, b)) * b;
  return ans;
}
void solve() {
  long long ans = 0;
  long long n, k;
  cin >> n;
  long long a[n];
  map<long long, long long> cnt;
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
    cnt[a[i]]++;
  }
  long long q;
  cin >> q;
  long long x, y;
  while (q--) {
    cin >> x >> y;
    long long temp = cnt[x];
    sum -= (temp * x);
    cnt[y] += temp;
    sum += (y * temp);
    cout << sum << "\n";
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  while (t--) solve();
  return 0;
}
