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

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

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

l = A("l")
c = B("c")
n = C("n")

l.w = n
c.z = n
c.r = l
n.v = c
assert n.v.z.v.txt == "
class A:
    def __init__(self, txt: str):
        self.w: C = None
        self.txt = txt

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

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

l = A("l")
c = B("c")
n = C("n")

l.w = n
c.z = n
c.r = l
n.v = c
assert n.v.z.v.txt == "c"