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

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

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

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

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

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

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

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

d.q = n
d.p = i
n.v = k
i.q = k
k.v = n
assert d.q.v.v.txt == "n"