#include<iostream>
#include<algorithm>
using namespace std;
long long S[100'005];
long long strength[100'005];
int main() {
int n, q;
cin >> n;
for (int i = 0;i < n;i++) {
cin >> S[i];
}
cin >> q;
sort(S, S + n);
strength[0] = S[0];
for (int i = 1; i < n; i++) {
strength[i] = strength[i-1] + S[i];
}
while (q--) {
long long p;
int best = -1;
cin >> p;
int start = 0, end = n - 1; long long mid;
while (start <= end) {
mid = start + (end - start) / 2;
if (p >= S[mid]) {
best = mid;
start = mid + 1;
}
else {
end = mid - 1;
}
}
if (best > 0) {
cout << best + 1 << " " << strength[best] << endl;
}
else { cout << "-1" << endl; }
}
return 0;
}
I2luY2x1ZGU8aW9zdHJlYW0+CiNpbmNsdWRlPGFsZ29yaXRobT4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmxvbmcgbG9uZyBTWzEwMCcwMDVdOwpsb25nIGxvbmcgc3RyZW5ndGhbMTAwJzAwNV07CgppbnQgbWFpbigpIHsKCglpbnQgbiwgcTsKCWNpbiA+PiBuOwoJZm9yIChpbnQgaSA9IDA7aSA8IG47aSsrKSB7CgkJY2luID4+IFNbaV07Cgl9CgoJY2luID4+IHE7CgoJc29ydChTLCBTICsgbik7CgoJc3RyZW5ndGhbMF0gPSBTWzBdOwoJZm9yIChpbnQgaSA9IDE7IGkgPCBuOyBpKyspIHsKCQlzdHJlbmd0aFtpXSA9IHN0cmVuZ3RoW2ktMV0gKyBTW2ldOwoJfQoKCXdoaWxlIChxLS0pIHsKCgkJbG9uZyBsb25nIHA7CgkJaW50IGJlc3QgPSAtMTsKCQljaW4gPj4gcDsKCgkJaW50IHN0YXJ0ID0gMCwgZW5kID0gbiAtIDE7IGxvbmcgbG9uZyBtaWQ7CgoJCXdoaWxlIChzdGFydCA8PSBlbmQpIHsKCQkJbWlkID0gc3RhcnQgKyAoZW5kIC0gc3RhcnQpIC8gMjsKCQkJaWYgKHAgPj0gU1ttaWRdKSB7CgkJCQliZXN0ID0gbWlkOwoJCQkJc3RhcnQgPSBtaWQgKyAxOwoJCQl9CgkJCWVsc2UgewoJCQkJZW5kID0gbWlkIC0gMTsKCQkJfQoJCX0KCgkJaWYgKGJlc3QgPiAwKSB7CgkJCWNvdXQgPDwgYmVzdCArIDEgPDwgIiAiIDw8IHN0cmVuZ3RoW2Jlc3RdIDw8IGVuZGw7CgkJfQoJCWVsc2UgeyBjb3V0IDw8ICItMSIgPDwgZW5kbDsgfQoJfQoJCglyZXR1cm4gMDsKfQ==