import java.util.Scanner ;
public class Main {
public static void main ( String[] args ) {
Scanner sc = new Scanner ( System.in ) ;
// 要測試的資料數量
for ( int data = sc.nextInt () ; data > 0 ; data -= 1 ) {
int[] array = new int [9] ; // 行列式,用一維陣列表示
// 行列式的輸入
for ( int element = 0 ; element < array.length ; element += 1 ) {
array[element] = sc.nextInt () ;
}
Main MTool = new Main () ; // 要用到class Main中的方法,先實體化
// 正數計算
int add = MTool.count ( array , 4 ) ; // 正數總和
// 負數計算
int reduce = MTool.count ( array , -2 ) ; // 負數總和
// 顯示計算結果
System.out.println ( ( add - reduce ) ) ;
}
}
// 計算:行列式、移動數量
int count ( int[] array , int move ) {
int total = 0 ; // 計算總和
for ( int seat = 0 ; seat < array.length ; seat += 3 ) {
int value = 1 , spot = seat ; // 計算的數值;元素位置
for ( int amount = 0 ; amount < 3 ; amount += 1 ) {
value *= array[spot] ;
spot += move ; // 下一個位置
if ( spot >= array.length ) {
spot -= 9 ; // 超過陣列元素上限時,設定到指定位置
}
else if ( spot < 0 ) {
spot += 9 ; // 低於陣列元素底線時,設定到指定的位置
}
}
total += value ; // 計算總和
}
return total ; // 回傳總和
}
}
留言列表