/******************************************************************************

Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, Java, PHP, Ruby, Perl,
C#, VB, Swift, Pascal, Fortran, Haskell, Objective-C, Assembly, HTML, CSS, JS, SQLite, Prolog.
Code, Compile, Run and Debug online from anywhere in world.

*******************************************************************************/
import java.util.*;
import javafx.util.*;

public class Main
{
	public static void main(String[] args) {
	
	Scanner sc=new Scanner(System.in);
	int t=sc.nextInt();
	for(int i=0;i<t;i++)
	{
	    int l=sc.nextInt();
	    int ones=sc.nextInt();
	    if(ones==0)
	    {
	        System.out.println(0);
	    }
	    else if(l<2)
	    {
	         System.out.println(ones); 
	    }
	    else if(l==2)
	    {
	       System.out.println(1+ones);  
	    }
	    else{
	        int fa=1;
	        int s=l-2+1;
	        for(int j=s;j<=l;j++)
	        {
	            fa*=j;
	        }
	        int ans=fa/2;
	       System.out.println(ans+ones);   
	        
	    }
	    
	    
	    
	    
	}
	
		
	}
}
