#include <bits/stdc++.h>
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return (a / gcd(a, b) * b); }
unsigned long long power(unsigned long long a, unsigned long long b) {
  a %= 1000000007;
  unsigned long long res = 1;
  while (b > 0) {
    if (b & 1) res = res * a % 1000000007;
    a = a * a % 1000000007;
    b >>= 1;
  }
  return res % 1000000007;
}
long long modmul(long long x, long long y) { return (x * y) % 1000000007; }
long long modadd(long long x, long long y) { return (x + y) % 1000000007; }
long long modsub(long long x, long long y) {
  return (x - y + 1000000007) % 1000000007;
}
long long fact[1000007] = {0};
void facto() {
  fact[0] = 1;
  fact[1] = 1;
  for (long long i = 2; i < 100007; i++)
    fact[i] = (fact[i - 1] * i) % 1000000007;
}
long long ncr(long long n, long long r) {
  long long res = 1;
  res = fact[n];
  res = (res * (power(fact[r], 1000000007 - 2))) % 1000000007;
  res = (res * (power(fact[n - r], 1000000007 - 2))) % 1000000007;
  return res;
}
long long npr(long long n, long long r) {
  long long res = 1;
  res = fact[n];
  res = (res * (power(fact[n - r], 1000000007 - 2))) % 1000000007;
  return res;
}
inline long long toint(const std::string &s) {
  std::stringstream ss;
  ss << s;
  long long x;
  ss >> x;
  return x;
}
inline std::string tostring(long long number) {
  std::stringstream ss;
  ss << number;
  return ss.str();
}
inline std::string tobin(long long x) { return std::bitset<63>(x).to_string(); }
using namespace std;
long long solve() {
  long long n;
  cin >> n;
  long long a[n];
  map<long long, set<long long> > mp;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    mp[a[i]].insert(i);
  }
  long long m;
  cin >> m;
  while (m--) {
    long long b, c;
    cin >> b >> c;
    long long sum = 0;
    for (auto it = mp[b].begin(); it != mp[b].end(); it++) {
      long long pos = *it;
      a[pos] = c;
      mp[c].insert(pos);
    }
    mp[b].clear();
    for (long long i = 0; i < n; i++) sum += a[i];
    cout << sum << '\n';
  }
  return 0;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  solve();
}
