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

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

f = A("f")
g = B("g")
k = B("k")
d = A("d")

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

f = A("f")
g = B("g")
k = B("k")
d = A("d")

f.o = k
g.o = k
k.o = g
d.o = g
assert k.o.o.o.txt == "g"