1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <algorithm>
#include <iostream>

using namespace std;

typedef long long ll;

string name;

int main() {
    cin >> name;
    int A, B;
    if (name[0] == 'A') {
        cin >> A >> B;
        int sh = abs(A - B) == 1 || abs(A - B) == 999 ? 2 : 1;
        cout << (A - 1 + sh) % 1000 + 1 << " " << (B - 1 + sh) % 1000 + 1 << "\n";
        cout.flush();
    } else {
        cin >> A >> B;
        int sh = abs(A - B) == 1 || abs(A - B) == 999 ? 2 : 1;
        cout << (A - 1 - sh + 1000) % 1000 + 1 << " " << (B - 1 - sh + 1000) % 1000 + 1 << "\n";
        cout.flush();
    }

    return 0;
}