import std.bigint,std.stdio,std.string;enum M=10^^9+7,S=M/213;long y,z,e,j;void i(){for(y=1,e=M-2;e;e/=2,z=z*z%M)y=e%2?y*z%M:y;}void f(int n){if(n>M-n)f(M-1-n),i,z=n%2?y:M-y;else{if(n%SY'];?[4+]B8PP'GY/I_,>,QOYMHFV!YYF#F7Q9T+>U\2,A-,]0O0+)HE?K#:@5^531P!:@2@#!CWQ;8&`[n/S*5+j++]-32;z=z*y%M;}}void main(){for(auto t=readln.chomp.BigInt;t--;){auto s=readln.split;BigInt r=s[0],l=s[1];r-=l-1;l=r-l;writeln(l<0||l/M