class A:
    def __init__(self, txt: str):
        self.x: 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.p: A = None
        self.y: B = None
        self.q: A = None
        self.txt = txt

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

n.x = k
d.v = i
k.p = n
k.q = n
k.y = h
h.v = i
i.v = d
b.p = n
b.q = n
b.y = h
assert b.y.v.v.v.txt == "
class A:
    def __init__(self, txt: str):
        self.x: 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.p: A = None
        self.y: B = None
        self.q: A = None
        self.txt = txt

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

n.x = k
d.v = i
k.p = n
k.q = n
k.y = h
h.v = i
i.v = d
b.p = n
b.q = n
b.y = h
assert b.y.v.v.v.txt == "i"