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

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

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

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

b = A("b")
m = B("m")
j = C("j")
n = D("n")
h = C("h")
c = C("c")
f = A("f")

b.q = m
b.z = m
b.t = j
b.s = f
m.x = n
j.s = b
j.w = h
j.p = h
n.t = j
h.s = f
h.w = c
h.p = c
c.s = b
c.w = j
c.p = h
f.q = m
f.z = m
f.t = c
f.s = b
assert b.z.x.t.s.s.z.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.t: C = None
        self.z: B = None
        self.s: A = None
        self.txt = txt

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

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

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

b = A("b")
m = B("m")
j = C("j")
n = D("n")
h = C("h")
c = C("c")
f = A("f")

b.q = m
b.z = m
b.t = j
b.s = f
m.x = n
j.s = b
j.w = h
j.p = h
n.t = j
h.s = f
h.w = c
h.p = c
c.s = b
c.w = j
c.p = h
f.q = m
f.z = m
f.t = c
f.s = b
assert b.z.x.t.s.s.z.txt == "m"