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

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

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

a = A("a")
m = B("m")
j = C("j")
h = B("h")

a.p = j
a.z = j
a.v = h
m.v = a
m.w = a
m.x = j
j.p = m
j.w = a
j.r = h
h.v = a
h.w = a
h.x = j
assert a.v.w.v.txt == "
class A:
    def __init__(self, txt: str):
        self.p: C = None
        self.z: C = None
        self.v: B = None
        self.txt = txt

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

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

a = A("a")
m = B("m")
j = C("j")
h = B("h")

a.p = j
a.z = j
a.v = h
m.v = a
m.w = a
m.x = j
j.p = m
j.w = a
j.r = h
h.v = a
h.w = a
h.x = j
assert a.v.w.v.txt == "h"