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

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

a = A("a")
d = B("d")
c = B("c")
k = A("k")
n = A("n")
l = A("l")

a.q = d
d.r = n
c.r = a
k.q = d
n.q = d
l.q = c
assert d.r.q.r.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.txt = txt

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

a = A("a")
d = B("d")
c = B("c")
k = A("k")
n = A("n")
l = A("l")

a.q = d
d.r = n
c.r = a
k.q = d
n.q = d
l.q = c
assert d.r.q.r.q.txt == "d"