#include <bits/stdc++.h>
using namespace std;
long long int fact(long long int n) {
  if (n == 0 || n == 1)
    return 1;
  else
    return (n * fact(n - 1) % 1000000007) % 1000000007;
}
int prime(long long int n) {
  for (int i = 2; i <= sqrt(n); i++) {
    if (n % i == 0) {
      return 0;
    }
  }
  return 1;
}
long long int gcd(long long int a, long long int b) {
  if (a == 0)
    return b;
  else
    return gcd(b % a, a);
}
long long int lcm(long long int a, long long int b) {
  return (a * b) / gcd(a, b);
}
int check_palin(string s) {
  string str = s;
  reverse(str.begin(), str.end());
  if (str == s)
    return 1;
  else
    return 0;
}
vector<long long int> divisors(long long int n) {
  vector<long long int> v;
  for (int i = 2; i <= sqrt(n); i++) {
    if (n % i == 0) {
      if (i == n / i)
        v.push_back(i);
      else
        v.push_back(i), v.push_back(n / i);
    }
  }
  return v;
}
long long int bin_expo(int x, int n) {
  if (n == 0)
    return 1;
  else if (n % 2 == 0)
    return bin_expo(x * x, n / 2);
  else
    return x * bin_expo(x * x, (n - 1) / 2);
}
long long int modular_expo(int x, int n, int M) {
  if (n == 0)
    return 1;
  else if (n % 2 == 0)
    return modular_expo((x * x) % M, n / 2, M);
  else
    return (x * modular_expo((x * x) % M, (n - 1) / 2, M)) % M;
}
void solve() {
  long long int n, ans = 0, z = 0;
  cin >> n;
  int a[n];
  map<int, int> mp;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    mp[a[i]]++;
    ans += a[i];
  }
  int x, y;
  cin >> z;
  while (z--) {
    cin >> x >> y;
    ans -= mp[x] * x;
    mp[y] += mp[x];
    ans += mp[x] * y;
    mp[x] = 0;
    cout << ans << "\n";
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  solve();
  return 0;
}
