#include <bits/stdc++.h>
#include <cstdint>
#include <iomanip>
#define PowerUp ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(0);
#define BattleMode ll t;cin>>t;while(t--)
#define Thor solve();
#define Thunder if(t>0){cout<<line;}
#define ll long long
#define line "\n"
#define line3 cout<<line;
#define stop string abnmj; cin>>abnmj;
#define tap "\t"
#define loop(end,char) for(ll char=0;char<end;char++)
#define loopr(end,char) for(int char=end-1;char>=0;char--)
#define arrin(name) loop(name.size(),p){cin>>name[p];}
#define print(name) for(auto ik:name){cout<<ik<<" ";}
#define print2(name) for(auto ik:name){cout<<ik.first<<" "<<ik.second<<line;}
#define temple template<typename t,typename v>
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
using namespace std;
const double pi = acos(-1);
const ll MOD = 1e9 + 7;
const double EPS = 1e-7;
int n, m, k;
char a[1005][1005];
vector<vector<vector<int> > > prefix(1005, vector<vector<int> >(1005, vector<int>(26,0)));
int distinct_values(vector<int> v)
{
int counter = 0;
for (auto it: v)
{
if (it > 0)
counter++;
}
return counter;
}
void print_frequancy(vector<int> freq)
{
for (int i = 0; i < 26; i++)
{
if (freq[i] > 0)
{
cout << static_cast<char>(i + 'A') << " " << freq[i] << line;
}
}
}
pair<int,int> check_window(const int sz)
{
//initiate fixed_size window
vector<int> freq(26, 0);
vector<pair<int, int> > res;
for (int k = 0; k < 26; k++)
freq[k] = prefix[sz][sz][k] - prefix[0][sz][k] - prefix[sz][0][k] + prefix[0][0][k];
int sum;
for (int i = sz; i <= n; i++)
{
sum = distinct_values(freq);
if (sum >= k)
res.push_back({i - sz+1, 1});
vector<int> temp(all(freq));
for (int j = sz; j < m; j++)
{
for (int k = 0; k < 26; k++)
{
temp[k] += prefix[i][j + 1][k] + prefix[i - sz][j][k] - prefix[i][j][k] - prefix[i - sz][j + 1][k];
temp[k] -= prefix[i][j - sz + 1][k] + prefix[i - sz][j - sz][k] - prefix[i][j - sz][k] - prefix[i - sz][j - sz + 1][k];
}
sum = distinct_values(temp);
if (sum >= k)
res.push_back({i - sz + 1, j - sz + 2});
}
if (i >= n)
break;
for (int k = 0; k < 26; k++)
{
freq[k] += prefix[i + 1][sz][k] + prefix[i][0][k] - prefix[i + 1][0][k] - prefix[i][sz][k];
freq[k] -= prefix[i - sz + 1][sz][k] + prefix[i - sz][0][k] - prefix[i - sz + 1][0][k] - prefix[i - sz][sz][k];
}
}
if (!res.empty())
return res.front();
return {-1, -1};
}
void solve()
{
cin >> n >> m >> k;
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= m; j++)
{
cin >> a[i][j];
}
}
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= m; j++)
{
for (int k = 0; k < 26; k++)
{
prefix[i][j][k] = prefix[i - 1][j][k] + prefix[i][j - 1][k] - prefix[i - 1][j - 1][k];
}
prefix[i][j][a[i][j] - 'A']++;
}
}
int left = 1, right = min(m, n) + 1;
pair<int, int> NO = {-1, -1};
while (left < right)
{
int mid = (right - left) / 2 + left;
pair<int, int> temp = check_window(mid);
if (temp != NO)
right = mid;
else
left = mid + 1;
}
pair<int, int> result = check_window(right);
if (result == NO)
cout << -1;
else
{
cout << right << line << result.first << " " << result.second << line;
}
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
freopen("error.txt", "w", stderr);
#endif
PowerUp
Thor
}