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

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

c = A("c")
m = B("m")
e = A("e")
d = B("d")
a = A("a")
l = A("l")

c.q = a
m.r = l
e.q = c
d.r = e
a.q = c
l.q = a
assert a.q.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.r: A = None
        self.txt = txt

c = A("c")
m = B("m")
e = A("e")
d = B("d")
a = A("a")
l = A("l")

c.q = a
m.r = l
e.q = c
d.r = e
a.q = c
l.q = a
assert a.q.q.q.q.q.q.txt == "a"