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

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

n = A("n")
i = B("i")
d = B("d")

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

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

n = A("n")
i = B("i")
d = B("d")

n.y = d
n.z = d
i.u = n
i.o = n
d.u = n
d.o = n
assert d.o.y.u.txt == "n"