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

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

i = A("i")
n = B("n")
b = B("b")
m = A("m")

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

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

i = A("i")
n = B("n")
b = B("b")
m = A("m")

i.u = b
n.z = m
n.y = b
b.z = i
b.y = n
m.u = n
assert b.z.u.y.txt == "n"