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

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

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

n = A("n")
i = B("i")
d = C("d")
k = B("k")

n.y = k
i.q = d
d.r = n
k.q = d
assert n.y.q.r.y.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.txt = txt

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

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

n = A("n")
i = B("i")
d = C("d")
k = B("k")

n.y = k
i.q = d
d.r = n
k.q = d
assert n.y.q.r.y.txt == "k"