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

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

k = A("k")
l = B("l")
c = B("c")
m = A("m")
d = A("d")
b = A("b")
i = A("i")

k.q = b
l.z = k
c.z = k
m.q = i
d.q = m
b.q = i
i.q = k
assert m.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.z: A = None
        self.txt = txt

k = A("k")
l = B("l")
c = B("c")
m = A("m")
d = A("d")
b = A("b")
i = A("i")

k.q = b
l.z = k
c.z = k
m.q = i
d.q = m
b.q = i
i.q = k
assert m.q.q.q.txt == "b"