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

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

j = A("j")
a = B("a")
e = B("e")
f = A("f")
g = B("g")

j.t = g
j.o = a
a.o = f
e.o = j
f.t = a
f.o = a
g.o = j
assert a.o.t.o.o.o.txt == "
class A:
    def __init__(self, txt: str):
        self.t: B = None
        self.o: B = None
        self.txt = txt

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

j = A("j")
a = B("a")
e = B("e")
f = A("f")
g = B("g")

j.t = g
j.o = a
a.o = f
e.o = j
f.t = a
f.o = a
g.o = j
assert a.o.t.o.o.o.txt == "f"