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

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

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

j = A("j")
h = B("h")
g = C("g")
i = C("i")

j.v = g
j.z = h
h.v = g
h.t = j
g.p = h
i.p = h
assert j.z.t.z.txt == "
class A:
    def __init__(self, txt: str):
        self.v: C = None
        self.z: B = None
        self.txt = txt

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

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

j = A("j")
h = B("h")
g = C("g")
i = C("i")

j.v = g
j.z = h
h.v = g
h.t = j
g.p = h
i.p = h
assert j.z.t.z.txt == "h"