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

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

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

k.q = a
m.x = i
m.o = d
i.q = a
a.q = k
d.x = k
d.o = g
l.x = k
l.o = m
g.x = a
g.o = m
assert i.q.q.q.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: A = None
        self.txt = txt

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

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

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