#include <iostream>
#include <cstring>
using namespace std;
int main() {
int n;
while( cin >> n && n){
int count = 0;
char *first = new char[n+1];
char *second = new char[n+1];
char *third = new char[2 * n+1];
char *result = new char[2 * n+1];
cin >> first;
cin >> second;
cin >> third;
while(strcmp(result, third) && (count < 51)){
for(int i = 0; i < n; i++){
result[2 * i] = second[i];
result[2 * i + 1] = first[i];
}
strncpy(first, &result[0], n);
strncpy(second, &result[n], n);
count++;
}
cout << ((count < 51) ? count : -1) << endl;
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8Y3N0cmluZz4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmludCBtYWluKCkgewoJaW50IG47Cgl3aGlsZSggY2luID4+IG4gJiYgbil7CgkJaW50IGNvdW50ID0gMDsKCQljaGFyICpmaXJzdCA9IG5ldyBjaGFyW24rMV07CgkJY2hhciAqc2Vjb25kID0gbmV3IGNoYXJbbisxXTsKCQljaGFyICp0aGlyZCA9IG5ldyBjaGFyWzIgKiBuKzFdOwoJCWNoYXIgKnJlc3VsdCA9IG5ldyBjaGFyWzIgKiBuKzFdOwoJCWNpbiA+PiBmaXJzdDsKCQljaW4gPj4gc2Vjb25kOwoJCWNpbiA+PiB0aGlyZDsKCQl3aGlsZShzdHJjbXAocmVzdWx0LCB0aGlyZCkgJiYgKGNvdW50IDwgNTEpKXsKCQkJZm9yKGludCBpID0gMDsgaSA8IG47IGkrKyl7CgkJCQlyZXN1bHRbMiAqIGldID0gc2Vjb25kW2ldOwoJCQkJcmVzdWx0WzIgKiBpICsgMV0gPSBmaXJzdFtpXTsKCQkJfQoJCQlzdHJuY3B5KGZpcnN0LCAmcmVzdWx0WzBdLCBuKTsKCQkJc3RybmNweShzZWNvbmQsICZyZXN1bHRbbl0sIG4pOwoJCQljb3VudCsrOwoJCX0KCQljb3V0IDw8ICgoY291bnQgPCA1MSkgPyBjb3VudCA6IC0xKSA8PCBlbmRsOwoJfQoJcmV0dXJuIDA7Cn0=
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