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

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

d = A("d")
a = B("a")
i = A("i")
g = B("g")
k = A("k")
m = B("m")

d.o = k
a.q = k
i.o = k
g.q = k
k.o = d
m.q = d
assert a.q.o.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.q: A = None
        self.txt = txt

d = A("d")
a = B("a")
i = A("i")
g = B("g")
k = A("k")
m = B("m")

d.o = k
a.q = k
i.o = k
g.q = k
k.o = d
m.q = d
assert a.q.o.o.o.o.o.txt == "d"