#include <bits/stdc++.h>
using namespace std;
typedef unsigned short int us;
typedef unsigned int ui;
typedef unsigned long long int ull;
typedef short int si;
typedef int in;
typedef long long int lli;
typedef char ch;
typedef float fl;
typedef double dou;
const double Pi = 2 * acos(0.0);
lli x;
template <typename t>
void vref(std::vector<t>& v, t n, t f(t)) {
  for (lli i = 1; i <= n; ++i) {
    t te;
    cin >> te;
    v.push_back(f(te));
  }
}
template <typename t>
t fx(t a) {
  if (a >= x)
    return a - x;
  else
    return a;
}
template <typename t>
void vre(std::vector<t>& v, t n) {
  for (lli i = 1; i <= n; ++i) {
    t te;
    cin >> te;
    v.push_back(te);
  }
}
template <typename t>
void vdu(std::vector<t> v) {
  if (v.size() == 0) {
    cout << "empty!!\n";
    return;
  }
  cout << v.size() << "(size)\n";
  for (lli i = 0; i <= v.size() - 1; ++i) cout << v[i] << " ";
  cout << "\n";
}
template <typename t, typename tt>
void mdu(std::map<t, tt> q) {
  cout << q.size() << "(size)\n";
  for (auto i = q.begin(); i != q.end(); ++i) {
    cout << "(" << i->first << ":";
    vdu(i->second);
    cout << ")\n";
  }
  cout << "\n";
}
template <typename t, typename tt>
tt mxmap(std::map<t, tt> q, char x) {
  std::pair<t, tt> mx;
  mx = {q.begin()->first, q.begin()->second};
  for (auto i = q.begin(); i != q.end(); ++i) {
    if (mx.x < max(mx.x, i->x)) mx = {i->first, i->second};
  }
  return mx;
}
template <typename t>
t power2(t a) {
  t val = 1, temp = 1000000007 - 2;
  while (temp > 0) {
    if (temp & 1) {
      val = (val * a) % 1000000007;
    }
    a = (a * a) % 1000000007;
    temp >>= 1;
  }
  return val;
}
template <typename t>
t ma(t x, t y) {
  return (((x) % 1000000007 + (y) % 1000000007) % 1000000007);
}
template <typename t>
t ms(t x, t y) {
  return ((((x) % 1000000007 - (y) % 1000000007) % 1000000007 + 1000000007) %
          1000000007);
}
template <typename t>
t mm(t x, t y) {
  return (((x) % 1000000007 * (y) % 1000000007) % 1000000007);
}
template <typename t>
t md(t a, t b) {
  return (((a) % 1000000007) * ((power2(b)) % 1000000007)) % 1000000007;
}
void solve() {
  std::vector<std::pair<lli, lli> > A_val_ind;
  lli N;
  cin >> N;
  std::map<lli, std::vector<lli> > A_map_val_ind;
  for (lli i = 1; i <= N; ++i) {
    lli tval;
    cin >> tval;
    A_val_ind.push_back({tval, i});
    A_map_val_ind[tval].push_back(i);
  }
  lli Q;
  cin >> Q;
  for (lli i = 1; i <= Q; ++i) {
    lli B, C;
    cin >> B >> C;
    A_map_val_ind[C].insert(A_map_val_ind[C].end(), A_map_val_ind[B].begin(),
                            A_map_val_ind[B].end());
    A_map_val_ind[B].clear();
    lli sum = 0;
    for (auto it = A_map_val_ind.begin(); it != A_map_val_ind.end(); ++it) {
      sum += (it->first) * (it->second.size());
    }
    cout << sum << endl;
  }
}
int main() {
  solve();
  return 0;
}
