#include <array>
#include <iostream>
#include <map>
#include <vector>

//! @brief Regard Map of {key, count} to record count of key, initialize with 0 if key not found, then add
//! adding to key's count.
template <typename Map, typename Value = typename Map::mapped_type>
Value &
MapAddCount(Map &map, typename Map::key_type key, Value adding)
{
    auto [it, flag] = map.try_emplace(key, 0);
    (void)flag;
    auto &count = it->second;
    count += adding;
    return count;
}

inline constexpr std::size_t BufferSize = 1024;

int
main()
{
    std::ios::sync_with_stdio(false);

    std::vector<int> bufferA;
    bufferA.resize(BufferSize, 0);
    std::vector<int> bufferB;
    bufferB.resize(BufferSize, 0);
    std::vector<int> bufferC;
    bufferC.resize(BufferSize, 0);

    std::vector<int> values;

    std::size_t valueCount;
    std::cin >> valueCount;

    auto usingValuesPtr = &bufferA;
    if (valueCount>BufferSize)
    {
        values.resize(valueCount);
        usingValuesPtr = &values;
    }
    auto &usingValues = *usingValuesPtr;

    for (std::size_t i = 0; i<valueCount; ++i)
    {
        std::cin >> usingValues[i];
    }

    std::size_t operationCount;
    std::cin >> operationCount;

    std::vector<int> oldValues;
    std::vector<int> newValues;

    auto usingOldValuesPtr = &bufferB;
    auto usingNewValuesPtr = &bufferC;
    if (operationCount>BufferSize)
    {
        oldValues.resize(operationCount);
        newValues.resize(operationCount);
        usingOldValuesPtr = &oldValues;
        usingNewValuesPtr = &newValues;
    }
    auto &usingOldValues = *usingOldValuesPtr;
    auto &usingNewValues = *usingNewValuesPtr;

    for (std::size_t i = 0; i<operationCount; ++i)
    {
        std::cin >> usingOldValues[i];
        std::cin >> usingNewValues[i];
    }

    long long sum = 0;
    std::map<int, int> valueCounts;
    for (auto &value : usingValues)
    {
        MapAddCount(valueCounts, value, 1);
        sum += value;
    }

    for (std::size_t i = 0; i<operationCount; ++i)
    {
        auto oldValue = usingOldValues[i];
        auto newValue = usingNewValues[i];

        auto &count = MapAddCount(valueCounts, oldValue, 0);

        sum -= static_cast<long long>(oldValue)*count;
        sum += static_cast<long long>(newValue)*count;

        MapAddCount(valueCounts, newValue, count);
        std::cout << sum << "\n";
    }
}
