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

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

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

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

h = A("h")
b = B("b")
e = C("e")
m = D("m")
j = D("j")
a = C("a")

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

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

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

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

h = A("h")
b = B("b")
e = C("e")
m = D("m")
j = D("j")
a = C("a")

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