//Su dung deque co do phuc tap O(2n)
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define all(a) (a).begin(), (a).end()
const int maxn = 1e3 + 1;
int val(char c) {
if (c >= '0' && c <= '9') return c - 48;
return c - 65 + 10;
}
int A[maxn];
deque<int> dq;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
string s;
int t, answer = INT_MAX;
cin >> t;
while (t--) {
int k, t, truyvan, result = 0;
cin >> s;
for (int i = 0; i < s.size(); ++i) {
A[i] = val(s[i]);
}
for (int k = 1; k <= s.size(); ++k) {
dq.clear();
int ma = 0;
for (int i = 0; i < s.size(); ++i) {
while (!dq.empty() && A[i] <= A[dq.back()]) {
dq.pop_back();
}
dq.push_back(i);
if (dq.front() <= i - k) {
dq.pop_front();
}
if (i >= k - 1) {
ma = max(ma, k * A[dq.front()]);
}
}
result = max(result, ma);
}
answer = min(answer, result);
}
cout << answer;
}
Ly9TdSBkdW5nIGRlcXVlIGNvIGRvIHBodWMgdGFwIE8oMm4pIAojaW5jbHVkZSA8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKI2RlZmluZSBsbCBsb25nIGxvbmcKI2RlZmluZSB1bGwgdW5zaWduZWQgbG9uZyBsb25nCiNkZWZpbmUgYWxsKGEpIChhKS5iZWdpbigpLCAoYSkuZW5kKCkKY29uc3QgaW50IG1heG4gPSAxZTMgKyAxOwppbnQgdmFsKGNoYXIgYykgewoJaWYgKGMgPj0gJzAnICYmIGMgPD0gJzknKSByZXR1cm4gYyAtIDQ4OwoJcmV0dXJuIGMgLSA2NSArIDEwOwp9CmludCBBW21heG5dOwpkZXF1ZTxpbnQ+IGRxOwppbnQgbWFpbigpIHsKCWlvc19iYXNlOjpzeW5jX3dpdGhfc3RkaW8oZmFsc2UpOwoJY2luLnRpZSgwKTsKCWNvdXQudGllKDApOwoJc3RyaW5nIHM7CglpbnQgdCwgYW5zd2VyID0gSU5UX01BWDsKCW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