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

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

h = A("h")
g = B("g")
f = B("f")
l = B("l")
k = B("k")

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

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

h = A("h")
g = B("g")
f = B("f")
l = B("l")
k = B("k")

h.o = k
g.o = h
f.o = h
l.o = h
k.o = h
assert h.o.o.o.txt == "k"