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

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

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

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

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

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

b.y = k
b.z = c
c.r = b
k.r = b
assert k.r.z.r.txt == "b"