#include<stdio.h>
int main(void){
  int t;
  int n,a,b,c,d;
  scanf("%d",&t);
  int i,j;
  int coin=0;
  int x=0;
  for(i=0;i<t;i++){
    scanf("%d%d%d%d",&a,&b,&c,&d);
    coin+=d;
    x+=1;
    coin+=a;
    x*=2;
    coin+=a;
    x*=2;
    coin+=b;
    x*=3;
    coin+=d;
    x-=1;
    printf("%d",coin);
  }
  return 0;
}