#include <iostream>
#include <cmath>
#include <cstring>
using namespace std;
int f[10001];
int E, F;
int main() {
//freopen("1.txt", "r", stdin);
int t;
cin >> t;
while(t--) {
cin >> E >> F;
int weigh = F - E;
for(int i = 0; i <= weigh; i++) f[i] = 99999999;
f[0] = 0;
int n;
cin >> n;
while(n--) {
int p, w;
cin >> p >> w;
for(int i = w; i <= weigh; i++)
f[i] = min(f[i], f[i - w] + p);
}
if(f[weigh] == 99999999)
cout << "This is impossible./n";
else
cout << "The minimum amount of money in the piggy-bank is "
<< f[weigh] << "./n";
}
return 0;
}