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

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

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

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

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

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