#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long INF = 2000000000000000000LL;
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, 1, -1};
int n, m;
vector<int> par, sz;
void make(int val)
{
par.resize(val + 1);
sz.resize(val + 1);
for (int i = 1; i <= val; ++i)
{
par[i] = i;
sz[i] = 1;
}
}
int fi(int v)
{
if (v == par[v])
return v;
return par[v] = fi(par[v]);
}
void uni(int u, int v)
{
int a = fi(u), b = fi(v);
if (a == b)
return;
if (a != b)
{
if (sz[a] < sz[b])
swap(a, b);
par[b] = a;
sz[a] += sz[b];
}
}
int ID(int i, int j)
{
return i * m + j;
}
void solve()
{
cin >> n >> m;
vector<vector<char>> a(n + 4, vector<char>(m + 4));
vector<vector<bool>> visited(n + 4, vector<bool>(m + 4, false));
make(n * m + max(n, m));
for (int i = 1; i <= n; ++i)
{
for (int j = 1; j <= m; ++j)
{
cin >> a[i][j];
visited[i][j] = false;
}
}
for (int i = 1; i <= n; ++i)
{
for (int j = 1; j <= m; ++j)
{
if (!visited[i][j] && a[i][j] == '#')
{
visited[i][j] = true;
queue<pair<int, int>> q;
q.push({i, j});
int u = fi(ID(i, j));
while (!q.empty())
{
pair<int, int> h = q.front();
q.pop();
int i1 = h.first, j1 = h.second;
for (int k = 0; k < 4; ++k)
{
int i2 = i1 + dx[k];
int j2 = j1 + dy[k];
if (i2 >= 1 && i2 <= n && j2 >= 1 && j2 <= m && !visited[i2][j2] && a[i2][j2] == '#')
{
int v = ID(i2, j2);
visited[i2][j2] = true;
uni(u, v);
q.push({i2, j2});
}
}
}
}
}
}
int ans = 0;
for (int i = 1; i <= n; ++i)
{
int cnt = 0;
set<int> s;
for (int j = 1; j <= m; ++j)
{
if (a[i][j] == '.')
cnt++;
if (a[i][j] == '#')
s.insert(fi(ID(i, j)));
}
if (i - 1 >= 1)
{
for (int j = 1; j <= m; ++j)
{
if (a[i - 1][j] == '#')
s.insert(fi(ID(i - 1, j)));
}
}
if (i + 1 <= n)
{
for (int j = 1; j <= m; ++j)
{
if (a[i + 1][j] == '#')
s.insert(fi(ID(i + 1, j)));
}
}
for (int x : s)
cnt += sz[x];
ans = max(ans, cnt);
}
for (int j = 1; j <= m; ++j)
{
int cnt = 0;
set<int> s;
for (int i = 1; i <= n; ++i)
{
if (a[i][j] == '.')
cnt++;
if (a[i][j] == '#')
s.insert(fi(ID(i, j)));
}
if (j - 1 >= 1)
{
for (int i = 1; i <= n; ++i)
{
if (a[i][j - 1] == '#')
s.insert(fi(ID(i, j - 1)));
}
}
if (j + 1 <= m)
{
for (int i = 1; i <= n; ++i)
{
if (a[i][j + 1] == '#')
s.insert(fi(ID(i, j + 1)));
}
}
for (int x : s)
cnt += sz[x];
ans = max(ans, cnt);
}
cout << ans;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t;
cin >> t;
while (t--)
{
solve();
cout << "\n";
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+Cgp1c2luZyBuYW1lc3BhY2Ugc3RkOwp0eXBlZGVmIGxvbmcgbG9uZyBsbDsKCmNvbnN0IGxvbmcgbG9uZyBJTkYgPSAyMDAwMDAwMDAwMDAwMDAwMDAwTEw7CmNvbnN0IGludCBkeFtdID0gezEsIC0xLCAwLCAwfTsKY29uc3QgaW50IGR5W10gPSB7MCwgMCwgMSwgLTF9OwppbnQgbiwgbTsKdmVjdG9yPGludD4gcGFyLCBzejsKCnZvaWQgbWFrZShpbnQgdmFsKQp7CiAgICBwYXIucmVzaXplKHZhbCArIDEpOwogICAgc3oucmVzaXplKHZhbCArIDEpOwogICAgZm9yIChpbnQgaSA9IDE7IGkgPD0gdmFsOyArK2kpCiAgICB7CiAgICAgICAgcGFyW2ldID0gaTsKICAgICAgICBzeltpXSA9IDE7CiAgICB9Cn0KCmludCBmaShpbnQgdikKewogICAgaWYgKHYgPT0gcGFyW3ZdKQogICAgICAgIHJldHVybiB2OwogICAgcmV0dXJuIHBhclt2XSA9IGZpKHBhclt2XSk7Cn0KCnZvaWQgdW5pKGludCB1LCBpbnQgdikKewogICAgaW50IGEgPSBmaSh1KSwgYiA9IGZpKHYpOwogICAgaWYgKGEgPT0gYikKICAgICAgICByZXR1cm47CiAgICBpZiAoYSAhPSBiKQogICAgewogICAgICAgIGlmIChzelthXSA8IHN6W2JdKQogICAgICAgICAgICBzd2FwKGEsIGIpOwogICAgICAgIHBhcltiXSA9IGE7CiAgICAgICAgc3pbYV0gKz0gc3pbYl07CiAgICB9Cn0KCmludCBJRChpbnQgaSwgaW50IGopCnsKICAgIHJldHVybiBpICogbSArIGo7Cn0KCnZvaWQgc29sdmUoKQp7CiAgICBjaW4gPj4gbiA+PiBtOwogICAgdmVjdG9yPHZlY3RvcjxjaGFyPj4gYShuICsgNCwgdmVjdG9yPGNoYXI+KG0gKyA0KSk7CiAgICB2ZWN0b3I8dmVjdG9yPGJvb2w+PiB2aXNpdGVkKG4gKyA0LCB2ZWN0b3I8Ym9vbD4obSArIDQsIGZhbHNlKSk7CgogICAgbWFrZShuICogbSArIG1heChuLCBtKSk7CgogICAgZm9yIChpbnQgaSA9IDE7IGkgPD0gbjsgKytpKQogICAgewogICAgICAgIGZvciAoaW50IGogPSAxOyBqIDw9IG07ICsraikKICAgICAgICB7CiAgICAgICAgICAgIGNpbiA+PiBhW2ldW2pdOwogICAgICAgICAgICB2aXNpdGVkW2ldW2pdID0gZmFsc2U7CiAgICAgICAgfQogICAgfQoKICAgIGZvciAoaW50IGkgPSAxOyBpIDw9IG47ICsraSkKICAgIHsKICAgICAgICBmb3IgKGludCBqID0gMTsgaiA8PSBtOyArK2opCiAgICAgICAgewogICAgICAgICAgICBpZiAoIXZpc2l0ZWRbaV1bal0gJiYgYVtpXVtqXSA9PSAnIycpCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIHZpc2l0ZWRbaV1bal0gPSB0cnVlOwogICAgICAgICAgICAgICAgcXVldWU8cGFpcjxpbnQsIGludD4+IHE7CiAgICAgICAgICAgICAgICBxLnB1c2goe2ksIGp9KTsKCiAgICAgICAgICAgICAgICBpbnQgdSA9IGZpKElEKGksIGopKTsKCiAgICAgICAgICAgICAgICB3aGlsZSAoIXEuZW1wdHkoKSkKICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICBwYWlyPGludCwgaW50PiBoID0gcS5mcm9udCgpOwogICAgICAgICAgICAgICAgICAgIHEucG9wKCk7CgogICAgICAgICAgICAgICAgICAgIGludCBpMSA9IGguZmlyc3QsIGoxID0gaC5zZWNvbmQ7CiAgICAgICAgICAgICAgICAgICAgZm9yIChpbnQgayA9IDA7IGsgPCA0OyArK2spCiAgICAgICAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgICAgICAgICBpbnQgaTIgPSBpMSArIGR4W2tdOwogICAgICAgICAgICAgICAgICAgICAgICBpbnQgajIgPSBqMSArIGR5W2tdOwoKICAgICAgICAgICAgICAgICAgICAgICAgaWYgKGkyID49IDEgJiYgaTIgPD0gbiAmJiBqMiA+PSAxICYmIGoyIDw9IG0gJiYgIXZpc2l0ZWRbaTJdW2oyXSAmJiBhW2kyXVtqMl0gPT0gJyMnKQogICAgICAgICAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICBpbnQgdiA9IElEKGkyLCBqMik7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICB2aXNpdGVkW2kyXVtqMl0gPSB0cnVlOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgdW5pKHUsIHYpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgcS5wdXNoKHtpMiwgajJ9KTsKICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgIH0KICAgIH0KCiAgICBpbnQgYW5zID0gMDsKCiAgICBmb3IgKGludCBpID0gMTsgaSA8PSBuOyArK2kpCiAgICB7CiAgICAgICAgaW50IGNudCA9IDA7CiAgICAgICAgc2V0PGludD4gczsKICAgICAgICBmb3IgKGludCBqID0gMTsgaiA8PSBtOyArK2opCiAgICAgICAgewogICAgICAgICAgICBpZiAoYVtpXVtqXSA9PSAnLicpCiAgICAgICAgICAgICAgICBjbnQrKzsKICAgICAgICAgICAgaWYgKGFbaV1bal0gPT0gJyMnKQogICAgICAgICAgICAgICAgcy5pbnNlcnQoZmkoSUQoaSwgaikpKTsKICAgICAgICB9CiAgICAgICAgaWYgKGkgLSAxID49IDEpCiAgICAgICAgewogICAgICAgICAgICBmb3IgKGludCBqID0gMTsgaiA8PSBtOyArK2opCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIGlmIChhW2kgLSAxXVtqXSA9PSAnIycpCiAgICAgICAgICAgICAgICAgICAgcy5pbnNlcnQoZmkoSUQoaSAtIDEsIGopKSk7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICAgICAgaWYgKGkgKyAxIDw9IG4pCiAgICAgICAgewogICAgICAgICAgICBmb3IgKGludCBqID0gMTsgaiA8PSBtOyArK2opCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIGlmIChhW2kgKyAxXVtqXSA9PSAnIycpCiAgICAgICAgICAgICAgICAgICAgcy5pbnNlcnQoZmkoSUQoaSArIDEsIGopKSk7CiAgICAgICAgICAgIH0KICAgICAgICB9CgogICAgICAgIGZvciAoaW50IHggOiBzKQogICAgICAgICAgICBjbnQgKz0gc3pbeF07CgogICAgICAgIGFucyA9IG1heChhbnMsIGNudCk7CiAgICB9CgogICAgZm9yIChpbnQgaiA9IDE7IGogPD0gbTsgKytqKQogICAgewogICAgICAgIGludCBjbnQgPSAwOwogICAgICAgIHNldDxpbnQ+IHM7CiAgICAgICAgZm9yIChpbnQgaSA9IDE7IGkgPD0gbjsgKytpKQogICAgICAgIHsKICAgICAgICAgICAgaWYgKGFbaV1bal0gPT0gJy4nKQogICAgICAgICAgICAgICAgY250Kys7CiAgICAgICAgICAgIGlmIChhW2ldW2pdID09ICcjJykKICAgICAgICAgICAgICAgIHMuaW5zZXJ0KGZpKElEKGksIGopKSk7CiAgICAgICAgfQogICAgICAgIGlmIChqIC0gMSA+PSAxKQogICAgICAgIHsKICAgICAgICAgICAgZm9yIChpbnQgaSA9IDE7IGkgPD0gbjsgKytpKQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBpZiAoYVtpXVtqIC0gMV0gPT0gJyMnKQogICAgICAgICAgICAgICAgICAgIHMuaW5zZXJ0KGZpKElEKGksIGogLSAxKSkpOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGlmIChqICsgMSA8PSBtKQogICAgICAgIHsKICAgICAgICAgICAgZm9yIChpbnQgaSA9IDE7IGkgPD0gbjsgKytpKQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBpZiAoYVtpXVtqICsgMV0gPT0gJyMnKQogICAgICAgICAgICAgICAgICAgIHMuaW5zZXJ0KGZpKElEKGksIGogKyAxKSkpOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgICAgIGZvciAoaW50IHggOiBzKQogICAgICAgICAgICBjbnQgKz0gc3pbeF07CgogICAgICAgIGFucyA9IG1heChhbnMsIGNudCk7CiAgICB9CgogICAgY291dCA8PCBhbnM7Cn0KCmludCBtYWluKCkKewogICAgaW9zX2Jhc2U6OnN5bmNfd2l0aF9zdGRpbyhmYWxzZSk7CiAgICBjaW4udGllKE5VTEwpOwogICAgY291dC50aWUoTlVMTCk7CgogICAgaW50IHQ7CiAgICBjaW4gPj4gdDsKICAgIHdoaWxlICh0LS0pCiAgICB7CiAgICAgICAgc29sdmUoKTsKICAgICAgICBjb3V0IDw8ICJcbiI7CiAgICB9CgogICAgcmV0dXJuIDA7Cn0K