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

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

a = A("a")
d = B("d")
j = A("j")
n = B("n")
b = B("b")

a.o = j
d.t = a
j.o = a
n.t = a
b.t = j
assert b.t.o.o.o.o.txt == "
class A:
    def __init__(self, txt: str):
        self.o: A = None
        self.txt = txt

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

a = A("a")
d = B("d")
j = A("j")
n = B("n")
b = B("b")

a.o = j
d.t = a
j.o = a
n.t = a
b.t = j
assert b.t.o.o.o.o.txt == "j"