• + 0 comments

    include

    using namespace std;

    int test(string s) { if (s.length() % 2 == 1) return -1; int n = s.length(); map mp; for (int i = 0; i < n / 2; i++) mp[s[i]]++; for (int i = n / 2; i < n; i++) if (mp[s[i]] > 0) mp[s[i]]--; int dem = 0; for (auto it : mp) dem += it.second; return dem; }

    int main() { int t; cin >> t; while (t--) { string s; cin >> s; cout << test(s) << endl; } return 0; }