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

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

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

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

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

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

n.o = i
i.u = n
j.o = i
b.o = i
assert b.o.u.o.u.txt == "n"