#include "bits/stdc++.h"
using namespace std;

struct chane {
	int id;
	string st;
};
struct ope {
	bool split;
	int a;
	int b;
};
int check_cut(chane&c) {
	int xnum = (count(c.st.begin(), c.st.end(), 'x'));
	int onum = (count(c.st.begin(), c.st.end(), 'o'));
	if (xnum == onum)return -1;
	else {
		assert(xnum < onum);
		int nowx = 0;
		int nowo = 0;
		for (int i = 0; i < c.st.size()-1; ++i) {
			if (c.st[i] == 'o')nowo++;
			else nowx++;
			if (nowo == nowx + (onum - xnum) - 1) {
				assert(c.st[0] == 'o' || c.st[i] == 'o');
				return i;
			}
			if (nowx + 1 == nowo) {
				assert(c.st[c.st.size() - 1] == 'o' || c.st[i + 1] == 'o');
				return i;
			}
		}
	}
	return -1;
}
int make_ox(chane&c) {
	if (c.st[0]!=c.st[1]) {
		return 1;
	}
	if (c.st[c.st.size() - 2]!=c.st[c.st.size() - 1]) {
		return c.st.size() - 3;
	}
	return -1;
}
int needo(chane&c) {
	int xnum = (count(c.st.begin(), c.st.end(), 'x'));
	int onum = (count(c.st.begin(), c.st.end(), 'o'));
	if (xnum != onum) {
		return -1;
	}
	else {
		if (c.st[0] == 'x')return 0;
		if (c.st[c.st.size() - 1])return 1;
		return -1;
	}
}


void cut_chane(vector<ope>&opes,const int place, const chane& ch,vector<chane>&newcs,int& nextid) {
	opes.push_back(ope{ true,ch.id,place });
	newcs.push_back(chane{ nextid++,ch.st.substr(0,place + 1) });
	newcs.push_back(chane{ nextid++,ch.st.substr(place + 1,ch.st.size() - place - 1) });
}
bool isok(const vector<chane>&cs) {
	return all_of(cs.begin(), cs.end(), [](const chane&c) { return c.st.size() <= 3; });
}
void solve(const string& ast) {
	vector <ope>opes;
	chane base(chane{ 0, ast });
	const int xnum = count(ast.begin(), ast.end(), 'x');
	if (ast.size() < 2 *xnum ) {
		cout << -1 << endl;
		return;
	}
	else if (ast.size() == 2 * xnum) {
		int num =0;
		while (base.st.size()>2) {
			if (make_ox(base) == 1) {
				opes.push_back(ope{ true,num,1 });
				num += 2;
				base.st = base.st.substr(2, base.st.size() - 2);
			}
			else {
				cout << -1 << endl;
				return;
			}
		}
	}
	else {
		vector<chane>cs;
		cs.push_back(chane{ 0,ast });
		int nextid = 1;
		while (!isok(cs)) {
			bool flag = true;
			while ( flag) {
				flag = false;
				{
					vector<chane>newcs;
					for (int i = 0; i < cs.size(); ++i) {
						if (cs[i].st.size() >= 3) {
							const int cut = make_ox(cs[i]);
							if (cut != -1) {
								flag = true;
								cut_chane(opes, cut, cs[i], newcs, nextid);
							}
							else {
								newcs.push_back(cs[i]);
							}
						}
						else if (cs[i].st.size() == 1) {
							newcs.push_back(cs[i]);
						}
					}
					cs = newcs;
				}
				if (isok(cs))break;
				{
					vector<chane>newcs;
					for (int i = 0; i < cs.size(); ++i) {
						if (cs[i].st.size() != 2) {
							newcs.push_back(cs[i]);
						}
					}
					cs = newcs;
				}
			}
			if (isok(cs))break;
			{
				vector<chane>newcs;
				for (int i = 0; i < cs.size(); ++i) {
					const int cut = check_cut(cs[i]);
					if (cut != -1) {
						cut_chane(opes, cut, cs[i], newcs, nextid);
					}
					else {
						newcs.push_back(cs[i]);
					}
				}
				cs = newcs;
			}
			if (isok(cs))break;
			{
				int aid = -1;
				for (int i = 0; i < cs.size(); ++i) {
					if (cs[i].st.size() == 1) {
						assert(cs[i].st[0] == 'o');
						aid = cs[i].id;
						break;
					}
				}
				if (aid != -1) {
					vector<chane>newcs;
					bool used = false;
					for (int i = 0; i < cs.size(); ++i) {
						if (cs[i].id == aid)continue;
						int aneed = needo(cs[i]);
						if (aneed == -1||used) {
							newcs.push_back(cs[i]);
						}
						else if (aneed == 0) {
							used = true;
							opes.push_back(ope{ false,aid,cs[i].id });
							newcs.push_back(chane{ nextid++,'o' + cs[i].st });
						}
						else {
							used = true;
							opes.push_back(ope{ false,cs[i].id,aid });
							newcs.push_back(chane{ nextid++, cs[i].st + 'o' });
						}
					}
					if (!used) {
						newcs.push_back(chane{ aid,"o" });
					}
					cs = newcs;
				}
			}
		}
	}
	cout << opes.size() << endl;
	for (auto op : opes) {
		if (op.split)cout << "split ";
		else cout << "join ";
		cout << op.a << " " << op.b << endl;
	}
}

int main() {
	int Q; cin >> Q;
	while (Q--) {
		string st; cin >> st;
		solve(st);
	}
	return 0;
}

Measured memory_bytes: 3168