#include <bits/stdc++.h>

#define ms(a,b) memset(a, b, sizeof(a))
#define rep(a,b,c) for(int a = (int)(b); a < (int)(c); a++)
#define fi first
#define se second
#define pb push_back
#define pf push_front
#define m_p(a,b) make_pair(a, b)
#define lson l,mid,o << 1
#define rson mid + 1,r,o << 1 | 1
#define ls o << 1
#define rs o << 1 | 1
#define inf 0x3f3f3f3f

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef pair<int,int> pii;

inline bool isdigit(char& ch) {
	return ch >= '0' && ch <= '9';
}
template<class T>
void read(T &x) {
	x = 0;
	ll f = 1;char ch = getchar();
	for (;!isdigit(ch);ch = getchar()) 
		if (ch == '-') f = -1;
	for (; isdigit(ch);ch = getchar())
		x = (x << 1) + (x << 3) + ch - '0';
	x *= f;
}
template<class T>
inline void write(T x) {
	if (x == 0) {putchar('0');return ;}
	if (x < 0) {putchar('-');x = -x;}
	int _stk[65],_top = 0;
	for (;x;x /= 10) _stk[++_top] = x % 10 + 48;
	for (;_top;_top--)putchar(_stk[_top]);
}

namespace Union {
	vector<int>fa;
	void Assign(int n) {
		fa.assign(n, -1);
	}
	int root(int x) {
		if (fa[x] < 0)
			return x;
		return fa[x] == x ? fa[x] : fa[x] = root(fa[x]);
	}
	bool same(int x, int y) {
		return root(x) == root(y);
	}
	void merge(int x, int y) {
		fa[root(x)] = root(y);
	}
}

using namespace Union;

int main () {
	int n;

	using P = pair<db, db>;
	using Edge = pair<db, pair<int, int>>;

	vector<P>pint;
	cin >> n;
	pint.resize(n);
	for (auto &[x, y] : pint)
		cin >> x >> y;
//	cout << pint.size();
	Assign(n + 2);
	int S  = n, T = n + 1;
	auto calc = [&](P a, P b) {return sqrt((a.fi-b.fi) * (a.fi-b.fi) + (a.se-b.se)*(a.se-b.se));};

	vector<Edge>edge;
	for (int i = 0; i < pint.size(); ++i) {
		edge.push_back({100+pint[i].se, {S, i}});
		edge.push_back({100-pint[i].se, {T, i}});
		for (int j = i + 1; j < pint.size(); ++j) {
			edge.pb({calc(pint[i], pint[j]), {i, j}});
		}
	}
	sort(edge.begin(), edge.end());
	db res = 0;
	for (auto E : edge) {
		merge(E.se.fi, E.se.se);
	//	cout << E.se.fi << " " << E.se.se << " " << E.fi<<endl;
		if (same(S, T)) {
			res = E.fi / 2.0;
			break;
		}
	}
	cout << fixed << setprecision(10) << res << endl;
	return 0;
}
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using uint = unsigned int;
#define rep(i,n) for(int i=0;i<int(n);i++)
#define rep1(i,n) for(int i=1;i<=int(n);i++)
#define per(i,n) for(int i=int(n)-1;i>=0;i--)
#define per1(i,n) for(int i=int(n);i>0;i--)
#define all(c) c.begin(),c.end()
#define si(x) int(x.size())
#define pb emplace_back
#define fs first
#define sc second
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
template<class T,class U> void chmax(T& x, U y){if(x<y) x=y;}
template<class T,class U> void chmin(T& x, U y){if(y<x) x=y;}
template<class T> void mkuni(V<T>& v){sort(all(v));v.erase(unique(all(v)),v.end());}
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

#ifdef LOCAL
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
void dmpr(ostream& os){os<<endl;}
template<class T,class... Args>
void dmpr(ostream&os,const T&t,const Args&... args){
	os<<t<<" ~ ";
	dmpr(os,args...);
}
#define shows(...) cerr << "LINE" << __LINE__ << " : ";dmpr(cerr,##__VA_ARGS__)
#define dump(x) cerr << "LINE" << __LINE__ << " : " << #x << " = {";  \
	for(auto v: x) cerr << v << ","; cerr << "}" << endl;
#else
#define show(x) void(0)
#define dump(x) void(0)
#define shows(...) void(0)
#endif

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);		//DON'T USE scanf/printf/puts !!
	cout << fixed << setprecision(20);
	int T; cin >> T;
	while(T--){
		string s; cin >> s;
		int N = si(s);
		if(s == string('a',N)){
			cout << -1 << endl;
			continue;
		}
		if(s[0] != 'a'){
			cout << 0 << endl;
			continue;
		}
		int j=-1;
		rep(i,N){
			if(s[i] != 'a'){
				j = i;
				break;
			}
		}
		string t = s;
		for(int i=j-1;i>=1;i--) swap(t[i],t[i+1]);
		if(t > "atcoder"){
			cout << j-1 << endl;
			continue;
		}
		cout << j << endl;
		continue;
	}
}
