#include <iostream>
#include <vector>
#include <algorithm>
int main()
{
int loop_iterations;
int temp;
std::vector<unsigned long>x;
std::cin >> loop_iterations;
for (int i = 0; i < loop_iterations; ++i)
{
std::cin >> temp;
x.insert(x.end(), temp);
}
std::sort(x.begin(), x.end());
std::cin >> loop_iterations;
for (int i = 0; i < loop_iterations; ++i)
{
std::cin >> temp;
if (temp == 1)
{
int eats = 0;
unsigned long source_weight;
unsigned long destination_weight;
std::cin >> source_weight;
std::cin >> destination_weight;
bool good = true;
bool reset = false;
std::vector<unsigned long> y = x;
while (source_weight < destination_weight)
{
bool changed = false;
for (std::vector<unsigned long>::reverse_iterator it = y.rbegin(); it != y.rend(); ++it)
{
if (*it < source_weight)
{
source_weight += *it;
y.erase(--it.base());
++eats;
changed = true;
break;
}
}
if (!changed)
{
good = false;
break;
}
}
std::cout << (good ? eats : -1)<<"\n";
}
else if (temp == 2)
{
std::cin >> temp;
std::vector<unsigned long>::iterator xd;
for (xd = x.begin(); xd != x.end() && *xd < temp; ++xd);
x.insert(xd, temp);
}
else
{
std::cin >> temp;
auto xd = std::find(x.begin(), x.end(), temp);
if (xd != x.end())
{
x.erase(xd);
}
}
}
}