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

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

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

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

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

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

n.y = f
m.u = f
f.u = m
j.y = f
assert j.y.u.u.u.txt == "m"