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

class B:
    def __init__(self, txt: str):
        self.w: D = None
        self.u: D = None
        self.txt = txt

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

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

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

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

class B:
    def __init__(self, txt: str):
        self.w: D = None
        self.u: D = None
        self.txt = txt

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

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

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

e.p = m
e.u = h
h.w = m
h.u = m
j.y = f
j.s = f
j.p = f
j.x = m
m.x = e
m.z = j
m.r = f
f.y = j
f.s = j
f.p = j
f.x = m
assert f.p.x.x.p.r.txt == "f"