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

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

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

h = A("h")
a = B("a")
j = C("j")
n = C("n")
g = C("g")

h.x = g
h.o = a
a.v = n
j.p = h
j.y = a
n.p = h
n.y = a
g.p = h
g.y = a
assert h.o.v.y.v.txt == "
class A:
    def __init__(self, txt: str):
        self.x: C = None
        self.o: B = None
        self.txt = txt

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

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

h = A("h")
a = B("a")
j = C("j")
n = C("n")
g = C("g")

h.x = g
h.o = a
a.v = n
j.p = h
j.y = a
n.p = h
n.y = a
g.p = h
g.y = a
assert h.o.v.y.v.txt == "n"