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

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

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

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

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

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

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