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

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

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

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

n.v = h
h.y = i
h.z = n
h.r = j
j.w = k
j.r = h
k.w = i
k.r = h
b.v = h
i.w = k
i.r = h
assert j.r.z.v.r.txt == "
class A:
    def __init__(self, txt: str):
        self.v: B = None
        self.txt = txt

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

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

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

n.v = h
h.y = i
h.z = n
h.r = j
j.w = k
j.r = h
k.w = i
k.r = h
b.v = h
i.w = k
i.r = h
assert j.r.z.v.r.txt == "j"