class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.x: B = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.r: A = None
        self.txt = txt

m = A("m")
j = B("j")
n = A("n")

m.y = j
m.x = j
j.r = n
n.y = j
n.x = j
assert j.r.y.r.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.x: B = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.r: A = None
        self.txt = txt

m = A("m")
j = B("j")
n = A("n")

m.y = j
m.x = j
j.r = n
n.y = j
n.x = j
assert j.r.y.r.txt == "n"