#include <bits/stdc++.h>
using namespace std;
//typeDef
typedef long long lli;
typedef long li;
typedef vector<int> vi;
typedef vector<li> vli;
typedef vector<lli> vlli;
typedef map<int, int> mii;
typedef set<int> seti;
typedef queue<int> qi;
typedef deque<int> dqi;
typedef stack<int> stacki;
typedef multiset<int> mseti;
//loop
#define rep(i, n) for(int i = 0; i < n; ++i)
#define fori(i, a, b) for(int i = a; i <= b; ++i)
#define ifor(i, a, b) for(int i = a; i >= b; --i)
//Pair
#define mp make_pair
#define iPair pair<int, int>
#define lliPair pair<lli, lli>
//Extras
#define mod1 1e9 + 7
#define mod2 1e9 + 9
#define inf int(1e9)
#define INF lli(1e18)
#define pi 3.14159265358979
#define pb push_back
#define pf push_front
#define popb pop_back()
#define popf pop_front()
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
#define iter(container, it) for(auto it = container.begin(); it != container.end(); ++it)
//functions
lli gcd(lli a, lli b) { return (a == 0) ? b : gcd(b % a, a); }
lli lcm(lli a, lli b) { return a / gcd(a, b) * b; }
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
while (t--){
int i = 0;
map< char, vector<int> > alpha;
string s;
cin >> s;
rep (i, s.size()){
alpha[s[i]].pb(i);
//as we know we can go to either next checkpoint or any other with the same ASCII value
//so inserting next checkpoint and similar checkpoint
if (i != s.size() - 1){
//we can't push i = n (out of bound)
alpha[s[i]].pb(i+1);
}
}
int dist[s.size()] ;
fill_n(dist, s.size(), inf);
//source cost = 0
dist[0] = 0;
bool marked[26] = {false};
//similar to bfs traversal
rep (i, s.size()){
if (!marked[s[i]-'a']){
marked[s[i]-'a'] = true;
//we traverse all checkpoints with same ASCII value and also the corresponding next checkpoints
for (auto x : alpha[s[i]]){
dist[x] = min(dist[x], dist[i] + abs(s[x] - s[i]));
}
}
}
//for testing each checkpoint cost from starting
rep (i, s.size()){
cout << dist[i] << " ";
}
cout << "\n";
cout << dist[s.size() - 1] << "\n";
}
return 0;
}
I2luY2x1ZGUgPG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U5KQojZGVmaW5lIElORiAgICAgICAgICAgICAgICAgICAgIGxsaSgxZTE4KQojZGVmaW5lIHBpICAgICAgICAgICAgICAgICAgICAgIDMuMTQxNTkyNjUzNTg5NzkKI2RlZmluZSBwYiAgICAgICAgICAgICAgICAgICAgICBwdXNoX2JhY2sKI2RlZmluZSBwZiAgICAgICAgICAgICAgICAgICAgICBwdXNoX2Zyb250CiNkZWZpbmUgcG9wYiAgICAgICAgICAgICAgICAgICAgcG9wX2JhY2soKQojZGVmaW5lIHBvcGYgICAgICAgICAgICAgICAgICAgIHBvcF9mcm9udCgpCiNkZWZpbmUgZmYgICAgICAgICAgICAgICAgICAgICAgZmlyc3QKI2RlZmluZSBzcyAgICAgICAgICAgICAgICAgICAgICBzZWNvbmQKI2RlZmluZSBhbGwodikgICAgICAgICAgICAgICAgICB2LmJlZ2luKCksIHYuZW5kKCkKI2RlZmluZSBpdGVyKGNvbnRhaW5lciwgaXQpICAgICBmb3IoYXV0byBpdCA9IGNvbnRhaW5lci5iZWdpbigpOyBpdCAhPSBjb250YWluZXIuZW5kKCk7ICsraXQpCgovL2Z1bmN0aW9ucwpsbGkgZ2NkKGxsaSBhLCBsbGkgYikgeyByZXR1cm4gKGEgPT0gMCkgPyBiIDogZ2NkKGIgJSBhLCBhKTsgfQpsbGkgbGNtKGxsaSBhLCBsbGkgYikgeyByZXR1cm4gYSAvIGdjZChhLCBiKSAqIGI7IH0KCmludCBtYWluKCkKewogICAgIGlvc19iYXNlOjpzeW5jX3dpdGhfc3RkaW8oMCk7CiAgICAgY2luLnRpZSgwKTsKCiAgICAgaW50IHQ7CiAgICAgY2luID4+IHQ7CiAgICAgd2hpbGUgKHQtLSl7CiAgICAgICAgICBpbnQgaSA9IDA7CiAgICAgICAgICBtYXA8IGNoYXIsIHZlY3RvcjxpbnQ+ID4gYWxwaGE7CiAgICAgICAgICBzdHJpbmcgczsKCiAgICAgICAgICBjaW4gPj4gczsKICAgICAgICAgIHJlcCAoaSwgcy5zaXplKCkpewogICAgICAgICAgICAgICBhbHBoYVtzW2ldXS5wYihpKTsKICAgICAgICAgICAgICAgLy9hcyB3ZSBrbm93IHdlIGNhbiBnbyB0byBlaXRoZXIgbmV4dCBjaGVja3BvaW50IG9yIGFueSBvdGhlciB3aXRoIHRoZSBzYW1lIEFTQ0lJIHZhbHVlCiAgICAgICAgICAgICAgIC8vc28gaW5zZXJ0aW5nIG5leHQgY2hlY2twb2ludCBhbmQgc2ltaWxhciBjaGVja3BvaW50CiAgICAgICAgICAgICAgIGlmIChpICE9IHMuc2l6ZSgpIC0gMSl7CiAgICAgICAgICAgICAgIAkJLy93ZSBjYW4ndCBwdXNoIGkgPSBuIChvdXQgb2YgYm91bmQpCiAgICAgICAgICAgICAgICAgICAgYWxwaGFbc1tpXV0ucGIoaSsxKTsKICAgICAgICAgICAgICAgfQogICAgICAgICAgfQoKICAgICAgICAgIGludCBkaXN0W3Muc2l6ZSgpXSA7CiAgICAgICAgICBmaWxsX24oZGlzdCwgcy5zaXplKCksIGluZik7CiAgICAgICAgICAvL3NvdXJjZSBjb3N0ID0gMAogICAgICAgICAgZGlzdFswXSA9IDA7CiAgICAgICAgICBib29sIG1hcmtlZFsyNl0gPSB7ZmFsc2V9OwoJCSAgCgkJICAvL3NpbWlsYXIgdG8gYmZzIHRyYXZlcnNhbAogICAgICAgICAgcmVwIChpLCBzLnNpemUoKSl7CiAgICAgICAgICAgICAgIGlmICghbWFya2VkW3NbaV0tJ2EnXSl7CiAgICAgICAgICAgICAgICAgICAgbWFya2VkW3NbaV0tJ2EnXSA9IHRydWU7CgkJCQkJCgkJCQkJLy93ZSB0cmF2ZXJzZSBhbGwgY2hlY2twb2ludHMgd2l0aCBzYW1lIEFTQ0lJIHZhbHVlIGFuZCBhbHNvIHRoZSBjb3JyZXNwb25kaW5nIG5leHQgY2hlY2twb2ludHMKICAgICAgICAgICAgICAgICAgICBmb3IgKGF1dG8geCA6IGFscGhhW3NbaV1dKXsKICAgICAgICAgICAgICAgICAgICAgICAgIGRpc3RbeF0gPSBtaW4oZGlzdFt4XSwgZGlzdFtpXSArIGFicyhzW3hdIC0gc1tpXSkpOwogICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgICAgCgkJICAvL2ZvciB0ZXN0aW5nIGVhY2ggY2hlY2twb2ludCBjb3N0IGZyb20gc3RhcnRpbmcKICAgICAgICAgIHJlcCAoaSwgcy5zaXplKCkpewogICAgICAgICAgICAgICBjb3V0IDw8IGRpc3RbaV0gPDwgIiAiOwogICAgICAgICAgfQogICAgICAgICAgY291dCA8PCAiXG4iOwoKICAgICAgICAgIGNvdXQgPDwgZGlzdFtzLnNpemUoKSAtIDFdIDw8ICJcbiI7CiAgICAgfQoKICAgICByZXR1cm4gMDsKfQ==