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

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

c = A("c")
k = B("k")
n = A("n")

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

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

c = A("c")
k = B("k")
n = A("n")

c.x = n
c.q = k
k.r = n
n.x = c
n.q = k
assert k.r.q.r.txt == "n"