#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<stdlib.h>
#include<algorithm>
#define getcx getchar_unlocked
#define pc(x) putchar_unlocked(x);
#ifndef ONLINE_JUDGE
#define getcx getchar
#endif
using namespace std;
#define ull unsigned long long int
#define lli long long int
#define li long int
#define ii int
#define mod 1000000007
inline int inp()
{
int n=0;
int ch=getcx();int sign=1;
while( ch < '0' || ch > '9' ){if(ch=='-')sign=-1; ch=getcx();}
while( ch >= '0' && ch <= '9' )
n = (n<<3)+(n<<1) + ch-'0', ch=getcx();
return n*sign;
}
inline long long in()
{
long long n=0;
long long ch=getcx();long long sign=1;
while( ch < '0' || ch > '9' ){if(ch=='-')sign=-1; ch=getcx();}
while( ch >= '0' && ch <= '9' )
n = (n<<3)+(n<<1) + ch-'0', ch=getcx();
return n*sign;
}
inline void write (lli n)
{
lli N = n, rev, count = 0;
rev = N;
if (N == 0) { pc('0'); pc('\n'); return ;}
while ((rev % 10) == 0) { count++; rev /= 10;} //obtain the count of the number of 0s
rev = 0;
while (N != 0) { rev = (rev<<3) + (rev<<1) + N % 10; N /= 10;} //store reverse of N in rev
while (rev != 0) { pc(rev % 10 + '0'); rev /= 10;}
while (count--) pc('0');
}
int main() {
// your code goes here
lli t,a,b;
t = in();
while ( t-- )
{
a= in(); b = in();
printf("%lld\n",(a%mod * b%mod - a%mod - b%mod));
}
return 0;
}
I2luY2x1ZGU8aW9zdHJlYW0+CiNpbmNsdWRlPGNzdGRpbz4KI2luY2x1ZGU8Y21hdGg+CiNpbmNsdWRlPGNzdHJpbmc+CiNpbmNsdWRlPHN0ZGxpYi5oPgojaW5jbHVkZTxhbGdvcml0aG0+CiNkZWZpbmUgZ2V0Y3ggZ2V0Y2hhcl91bmxvY2tlZAojZGVmaW5lIHBjKHgpIHB1dGNoYXJfdW5sb2NrZWQoeCk7CiNpZm5kZWYgT05MSU5FX0pVREdFCiAgICAjZGVmaW5lIGdldGN4IGdldGNoYXIKI2VuZGlmCnVzaW5nIG5hbW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