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

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

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

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

h = A("h")
m = B("m")
g = C("g")
j = D("j")
f = C("f")
n = A("n")
l = D("l")

h.y = n
h.z = m
h.r = f
h.q = j
m.p = f
m.y = h
m.v = l
m.w = l
g.w = m
j.z = m
j.r = m
f.w = m
n.y = h
n.z = m
n.r = f
n.q = j
l.z = m
l.r = m
assert n.r.w.p.w.p.txt == "
class A:
    def __init__(self, txt: str):
        self.y: A = None
        self.z: B = None
        self.r: C = None
        self.q: D = None
        self.txt = txt

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

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

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

h = A("h")
m = B("m")
g = C("g")
j = D("j")
f = C("f")
n = A("n")
l = D("l")

h.y = n
h.z = m
h.r = f
h.q = j
m.p = f
m.y = h
m.v = l
m.w = l
g.w = m
j.z = m
j.r = m
f.w = m
n.y = h
n.z = m
n.r = f
n.q = j
l.z = m
l.r = m
assert n.r.w.p.w.p.txt == "f"