#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>
#include<string.h>
#include<math.h>
#include<time.h>
const char symbollist[] = "+-*/()$;" ;//??????????????????
char SymbolJudge(char c, const char* str)//?????????????????¢??°
{
  for(size_t i = 0; str[i] != '\0'; ++i )
  {
    if( c == str[i])
    {
      return str[i] ;
    }
  }
  return 0 ;
}

int Judge(char *str)//()????????????????????????????????¢??°
{
  int pa_n = 0;
  for(size_t i = 0; str[i] != '\0'; ++i )
  {
    if(str[i] == '('){
      ++pa_n ;
    }
  }
  return pa_n ;
}

int Str(const char* str,const char* tar,const char* bul){//?????????????????¢??°
  char *temp ;
  size_t slen = strlen(str) ;
  size_t tlen = strlen(tar) ;
  size_t blen = strlen(bul) ;
  if((temp = strstr(str,tar)) == NULL){
    return 0 ;
  }
  memmove(temp + blen,temp + tlen,slen - (temp + tlen - str) + 1 ) ;
  memcpy(temp, bul , blen) ;
  return 1 ;
}
const int N = 200;
double EasyCalc(char *string){//()??????????¨????????????¢??°
  char formula[100] = {}, operators[N], temp[N], c ;
  size_t i, j = 0, nu_n = 0, op_n = 0 ;
  int tmp = 0  ;
  double num[N] ;
  strcpy(formula,string ) ;
  while(Str(formula," ","")) ;
  strcat(formula,";") ;
  for(i = 0,j = 0; formula[i] != '\0'; ++ i){
    if(SymbolJudge(formula[i], symbollist) == '-'){
      if(i == 0 || SymbolJudge(formula[i-1], symbollist) != 0){
        temp[j] = formula[i] ;
        ++j ;
        operators[op_n] = '+';
      }
      else{
        operators[op_n] = formula[i] ;
        ++op_n ;
        j = 0 ;
        num[nu_n] = atof(temp) ;
        ++ nu_n ;
        memset(temp,'\0', N);
      }
    }
    else if((c =SymbolJudge(formula[i], symbollist)) != 0){
      if(c != '('){
        operators[op_n] = formula[i] ;
        ++op_n ;
        j = 0 ;
        num[nu_n] = atof(temp) ;
        ++ nu_n ;
        memset(temp,'\0', N);
      }
    }
    else{
      temp[j] = formula[i] ;
      ++j ;
    }
  }
  tmp = 0 ;
  while(1){
    if((c=SymbolJudge(operators[tmp], symbollist) ) == ';'){
      break ;
    }
    switch(c){
      case '*':
        num[tmp] *= num[tmp + 1];
        num[tmp + 1] = 0 ;
        operators[tmp] = '\0' ;
        break ;
      case '/':
        num[tmp] /= num[tmp + 1];
        num[tmp + 1] = 0 ;
        operators[tmp] = '\0' ;
        break ;
      default:
        ++tmp ;
        break ;
    }
    for(j = 0; j < nu_n - 1; ++ j){
      if(num[j] == 0){
        num[j] = num[j + 1] ;
        num[j + 1] = 0 ;
      }
    }
    for(j = 0; j < op_n - 1; ++ j){
      if(operators[j] == '\0'){
        operators[j] = operators[j+1] ;
        operators[j + 1] = '\0' ;
      }
    }
  }
  tmp = 0 ;
  while(1){
    if((c=SymbolJudge(operators[0],symbollist)) == ';'){
      break ;
    }
    switch(c){
      case '+':
        num[tmp] += num[tmp + 1] ;
        num[tmp + 1] = 0 ;
        operators[tmp] = '\0' ;
        break ;
      case '-':
        num[tmp] -= num[tmp + 1] ;
        num[tmp + 1] = 0 ;
        operators[tmp] = '\0' ;
        break ;
      default:
        ++ tmp ;
        break ;
    }
    for(j = 0; j < nu_n - 1; ++ j){
      if(num[j] == 0){
        num[j] = num[j + 1] ;
        num[j + 1] = 0 ;
      }
    }
    for(j = 0; j < op_n - 1; ++ j){
      if(operators[j] == '\0'){
        operators[j] = operators[j+1] ;
        operators[j + 1] = '\0' ;
      }
    }
  }
  return num[0] ;
}
double Calculation(char *string)//???????????£??????????¨??????????
{
//   char* string = const_cast<char*>(str.c_str());
  bool flag = false ;
  char formula[N], formula1[N] = {}, operators[N], temp[N], c, buf[N] ;
  int flag_p = 0, pa_n = 0 ;
  size_t i, j = 0, nu_n = 0, op_n = 0, tmp = 0 ;
  double num[N] , ans;
  strcpy(formula,string ) ;
  while(1){//()??????????¨????????????¨???
    flag_p = Judge(formula) ;//()??????????????????????????????
    if(flag_p == 0 ){
      break ;
    }
    for(i = 0,j = 0,pa_n =0; formula[i] != '\0' ; ++ i){
      c = SymbolJudge(formula[i],symbollist) ;
      if(c == '('){
        ++pa_n ;
        if(flag_p == pa_n){
          formula[i] = '$' ;
          flag = true ;
        }
        j = 0;
        memset(formula1,'\0',N) ;
      }
      if(flag_p == pa_n){
        if(c == ')'){
          formula[i] = ' ' ;
          while(Str(formula1," ","")) ;
          while(Str(formula1,"\n","")) ;
          ans = EasyCalc(formula1) ;
          break ;
        }
        else{
          if(flag){
            flag = !flag ;
          }
          else{
            formula1[j] = formula[i] ;
            formula[i] = ' ' ;
            ++ j ;
          }
        }
      }
    }
    while(Str(formula," ","")) ;
    for(i = 0,j = 0; formula[i] != '\0' ; ++ i){
      c = SymbolJudge(formula[i],symbollist) ;
      if(c == '$'){
        sprintf(buf,"%lf",ans) ;
        Str(formula,"$", buf) ;
        break ;
      }
    }
  }

  strcat(formula,";") ;//????°?????????????????????§???????????¨???????????????????????????????¨?

  Str(formula,")","") ;
  for(i = 0,j = 0; formula[i] != '\0'; ++ i){
    if(SymbolJudge(formula[i], symbollist) == '-'){
      if(formula[i+1] != '\0' && SymbolJudge(formula[i+1], symbollist) == '-'){
        num[nu_n] = -1 ;
        ++nu_n ;
        operators[op_n] = '*' ;
        ++op_n ;
      }
      else if(i == 0 || SymbolJudge(formula[i-1], symbollist) != 0){//????????°??????????????????
        temp[j] = formula[i] ;
        ++j ;
        operators[op_n] = '+';
      }
      else{//???????????°?????¨???????????????????????????
        operators[op_n] = formula[i] ;//????????????????´?
        ++op_n ;
        j = 0 ;
        num[nu_n] = atof(temp) ;
        ++ nu_n ;
        memset(temp,'\0', N);
      }
    }
    else if((c =SymbolJudge(formula[i], symbollist)) != 0){//????????????????????°??§???????????§??????
      if(c != '('){
        operators[op_n] = formula[i] ;
        ++op_n ;
        j = 0 ;
        num[nu_n] = atof(temp) ;
        ++ nu_n ;
        memset(temp,'\0', N);
      }
    }
    else{//???????????§??????????????°??§??????
      temp[j] = formula[i] ;
      ++j ;
    }
  }
  while(1){//*/??????????????????
//         printf("%lf\n",num[nu_n-1]) ;
    if((c=SymbolJudge(operators[tmp], symbollist) ) == ';'){//???????????????????????????
      break ;
    }
    switch(c){//????´?????????????????????????????????£?????????????????????
      case '*':
        num[tmp] *= num[tmp + 1];
        num[tmp + 1] = INFINITY ;//????????¨?????\?????????????????¨??????
        operators[tmp] = '\0' ;//????????¨?????\???
        break ;
      case '/':
        num[tmp] /= num[tmp + 1];
        num[tmp + 1] = INFINITY ;
        operators[tmp] = '\0' ;
        break ;
      default://+-???????????§????¨?????????????
        ++tmp ;
        break ;
    }
    for(j = 0; j < nu_n - 1; ++ j){//????????¨?????\????????????????????????????????°????????????
      if(num[j] == INFINITY){
        num[j] = num[j + 1] ;
        num[j + 1] = INFINITY ;
      }
    }
    for(j = 0; j < op_n - 1; ++ j){//????§????
      if(operators[j] == '\0'){
        operators[j] = operators[j+1] ;
        operators[j + 1] = '\0' ;
      }
    }
  }
  tmp = 0 ;
  while(1){//+-?????????
    if((c=SymbolJudge(operators[0],symbollist)) == ';'){
      break ;
    }
    switch(c){//*/??¨?????????????????§??????
      case '+':
        num[tmp] += num[tmp + 1] ;
        num[tmp + 1] = INFINITY ;
        operators[tmp] = '\0' ;
        break ;
      case '-':
        num[tmp] -= num[tmp + 1] ;
        num[tmp + 1] = INFINITY ;
        operators[tmp] = '\0' ;
        break ;
      default:
        break ;
    }
    for(j = 0; j < nu_n - 1; ++ j){
      if(num[j] == INFINITY){
        num[j] = num[j + 1] ;
        num[j + 1] = INFINITY ;
      }
    }
    for(j = 0; j < op_n - 1; ++ j){
      if(operators[j] == '\0'){
        operators[j] = operators[j+1] ;
        operators[j + 1] = '\0' ;
      }
    }
  }
  return num[0] ;//??°????????????????????????????????????????´??????????
}

int main(){
  int n;
  scanf("%d",&n);
  char str[N];
  for(int i = 0; i < n; ++i){
    scanf("%s",str);
    int ans = Calculation(str);
    printf("%d\n", ans);
  }
  return 0;
}