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

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

a = A("a")
k = B("k")
l = B("l")
g = A("g")
d = B("d")

a.o = g
k.o = d
l.o = k
g.o = a
d.o = k
assert g.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.o: B = None
        self.txt = txt

a = A("a")
k = B("k")
l = B("l")
g = A("g")
d = B("d")

a.o = g
k.o = d
l.o = k
g.o = a
d.o = k
assert g.o.o.o.o.txt == "g"