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

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

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

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

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

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

h.o = e
e.x = h
f.o = e
a.o = e
g.o = e
assert g.o.x.o.x.o.txt == "e"