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

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

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

d = A("d")
k = B("k")
l = C("l")

d.x = l
k.x = l
k.r = l
k.w = d
l.w = d
l.p = d
assert k.r.w.x.txt == "
class A:
    def __init__(self, txt: str):
        self.x: C = None
        self.txt = txt

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

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

d = A("d")
k = B("k")
l = C("l")

d.x = l
k.x = l
k.r = l
k.w = d
l.w = d
l.p = d
assert k.r.w.x.txt == "l"