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

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

class C:
    def __init__(self, txt: str):
        self.u: A = None
        self.txt = txt

d = A("d")
g = B("g")
k = C("k")
m = B("m")
b = A("b")

d.v = k
d.w = k
d.p = g
g.s = m
g.z = k
k.u = d
m.s = g
m.z = k
b.v = k
b.w = k
b.p = m
assert b.p.z.u.p.txt == "
class A:
    def __init__(self, txt: str):
        self.v: C = None
        self.w: C = None
        self.p: B = None
        self.txt = txt

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

class C:
    def __init__(self, txt: str):
        self.u: A = None
        self.txt = txt

d = A("d")
g = B("g")
k = C("k")
m = B("m")
b = A("b")

d.v = k
d.w = k
d.p = g
g.s = m
g.z = k
k.u = d
m.s = g
m.z = k
b.v = k
b.w = k
b.p = m
assert b.p.z.u.p.txt == "g"