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

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

a = A("a")
i = B("i")
d = A("d")
n = B("n")
c = B("c")

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

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

a = A("a")
i = B("i")
d = A("d")
n = B("n")
c = B("c")

a.s = i
a.q = d
i.r = c
d.s = n
d.q = a
n.r = c
c.r = i
assert i.r.r.r.r.r.txt == "c"