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

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

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

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

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

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

k.w = n
k.r = n
a.x = n
n.w = k
n.r = k
assert k.w.w.w.txt == "n"