#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int p = 998244353;
void solve(int n, int m) {
}
int main() {
// ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int T;
cin >> T;
//思路:贪心+按位或;遍历整个矩阵,都按位或就可以找到最大权值。
//知识点:按位或'|'性质是'1'的优先级最高。只要矩阵上各个位上高位'1'越多,他的权值就越大。
while (T--) {
int n, m;
cin >> n >> m;
int ans = 0;
//从(0,0)开始遍历,x 是存储临时位置
for (int i = 0, x; i < n * m; i++) {
cin >> x;
ans |= x;
}
cout << ans << endl;
}
return 0;
}

京公网安备 11010502036488号