Given a square matrix** mat[][] **of size** N*N**, print the **sum of upper and lower triangular elements**. Upper Triangle consists of elements on the diagonal and above it. Lower triangle consists of elements on the diagonal and below it.

**Input:**

The first line consists of an integer **T** i.e number of test cases. The first line of each test case consists of an integer **N **denoting the size of the matrix. The next line contains **N*N** spaced separated integers.

**Output:**

For each testcase, in a new line, print the required output.

**Constraints:**

1 <= T <= 100

1 <= N <= 100

1 <= mat[i][j] <= 100

**Example:
Input:**

2

3

6 5 4 1 2 5 7 9 7

2

5 7 8 9

29 32

21 22

**Explanation:
Testcase1: **The given matrix is

6 5 4

1 2 5

7 9 7

The elements of upper triangle are

6 5 4

2 5

7

Sum of these elements is 6+5+4+2+5+7=29

The elements of lower triangle are

6

1 2

7 9 7

Sum of these elements is 6+1+2+7+9+7= 32

Author: saksham0751

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

VivSisMMM | 164 |

d_Coder00 | 163 |

ajayjadhav35 | 153 |

Astikeysingh | 148 |

Sathvik Avasarala | 143 |

Pulkit__Sharma__ | 658 |

Anirban166 | 565 |

abducodes | 542 |

Sathvik Avasarala | 506 |

Found_me | 494 |

blackshadows | 5331 |

Ibrahim Nash | 5219 |

akhayrutdinov | 5111 |

mb1973 | 4929 |

Quandray | 4559 |

Login to report an issue on this page.