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

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

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

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

h = A("h")
l = B("l")
f = C("f")
e = D("e")
k = A("k")
c = D("c")
d = C("d")
b = C("b")

h.p = b
h.w = k
l.x = d
l.z = h
l.w = k
f.r = k
f.v = l
f.x = e
f.z = d
e.u = f
e.s = c
k.p = b
k.w = h
c.u = b
c.s = e
d.r = k
d.v = l
d.x = c
d.z = b
b.r = h
b.v = l
b.x = c
b.z = f
assert d.r.p.z.txt == "
class A:
    def __init__(self, txt: str):
        self.p: C = None
        self.w: A = None
        self.txt = txt

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

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

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

h = A("h")
l = B("l")
f = C("f")
e = D("e")
k = A("k")
c = D("c")
d = C("d")
b = C("b")

h.p = b
h.w = k
l.x = d
l.z = h
l.w = k
f.r = k
f.v = l
f.x = e
f.z = d
e.u = f
e.s = c
k.p = b
k.w = h
c.u = b
c.s = e
d.r = k
d.v = l
d.x = c
d.z = b
b.r = h
b.v = l
b.x = c
b.z = f
assert d.r.p.z.txt == "f"