#include <bits/stdc++.h>
using namespace std;
template <typename T>
T gcd(T a, T b) {
  while (b) b ^= a ^= b ^= a %= b;
  return a;
}
template <typename T>
T setbit(T mask, T pos) {
  return mask |= (1 << pos);
}
template <typename T>
T resetbit(T mask, T pos) {
  return mask &= ~(1 << pos);
}
template <typename T>
T togglebit(T mask, T pos) {
  return mask ^= (1 << pos);
}
template <typename T>
T checkbit(T mask, T pos) {
  return (bool)(mask & (1 << pos));
}
template <typename T>
T lcm(T a, T b) {
  return (a / gcd(a, b)) * b;
}
template <typename T>
T modu(T a, T b) {
  return (a < b ? a : a % b);
}
template <typename T>
T mod_neg(T a, T b) {
  a = 1000000007(a, b);
  if (a < 0) {
    a += b;
  }
  return a;
}
template <typename T>
T expo(T e, T n) {
  T x = 1, p = e;
  while (n) {
    if (n & 1) x = x * p;
    p = p * p;
    n >>= 1;
  }
  return x;
}
template <typename T>
T mod_inverse(T a, T n) {
  T x, y;
  T d = extended_euclid(a, n, x, y);
  return (d > 1 ? -1 : mod_neg(x, n));
}
template <typename T>
T power(T e, T n, T m) {
  T x = 1, p = e;
  while (n) {
    if (n & 1) x = 1000000007(x * p, m);
    p = 1000000007(p * p, m);
    n >>= 1;
  }
  return x;
}
template <typename T>
T powerL(T e, T n, T m) {
  T x = 1, p = e;
  while (n) {
    if (n & 1) x = mulmod(x, p, m);
    p = mulmod(p, p, m);
    n >>= 1;
  }
  return x;
}
bool Pow2(int n) { return n && (!(n & (n - 1))); }
void printc(vector<char>& result) {
  for (auto r : result) cout << r << " ";
  cout << '\n';
}
void printl(vector<long long>& result) {
  for (auto r : result) cout << r << " ";
  cout << '\n';
}
void print(vector<int>& result) {
  for (auto r : result) cout << r << " ";
  cout << '\n';
}
int binpow(int a, int b) {
  if (b == 0) return a;
  int res = binpow(a, b / 2);
  if (b % 2)
    return res * res * a;
  else
    return res * res;
}
long long pow(long long a, long long b) {
  long long res = 1;
  while (b) {
    if (b & 1) res = res * a;
    a = a * a;
    b >>= 1;
  }
  return res;
}
int modpow(int a, int b, int m) {
  int ans = 1;
  while (b) {
    if (b & 1) ans = (ans * a) % m;
    b /= 2;
    a = (a * a) % m;
  }
  return ans;
}
long long ncr(long long n, long long k) {
  long long res = 1;
  if (k > n - k) k = n - k;
  for (long long i = 0; i < k; ++i) {
    res *= (n - i);
    res /= (i + 1);
  }
  return res;
}
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
int find(int a, vector<int>& par) {
  if (par[a] == a) return a;
  return par[a] = find(par[a], par);
}
void merge(int a, int b, vector<int>& par, int& count, vector<int>& size) {
  a = find(a, par);
  b = find(b, par);
  if (a == b) return;
  count++;
  if (size[a] > size[b]) {
    size[a] += size[b];
    par[b] = a;
  } else {
    size[b] += size[a];
    par[a] = b;
  }
}
vector<int> factor(int a) {
  vector<int> f;
  for (int i = 3; i * i <= a; i++) {
    if (a % i == 0) {
      f.push_back(i);
      if (a / i != i) f.push_back(a / i);
    }
  }
  return f;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int test;
  test = 1;
  while (test--) {
    int n;
    cin >> n;
    int sum = 0;
    unordered_map<int, int> mp;
    for (int(i) = 0; (i) < (int)(n); ++(i)) {
      int a;
      cin >> a;
      sum += a;
      mp[a]++;
    }
    int q;
    cin >> q;
    while (q--) {
      int a, b;
      cin >> a >> b;
      sum -= (mp[a]) * a;
      sum += mp[a] * b;
      mp[b] += mp[a];
      mp[a] = 0;
      cout << sum << '\n';
    }
  }
}
