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

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

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

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

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

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

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

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

k.x = d
a.w = k
a.y = k
d.r = a
assert d.r.y.x.txt == "d"