class A:
    def __init__(self, txt: str):
        self.q: D = None
        self.txt = txt

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

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

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

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

f.q = a
l.z = j
l.w = m
e.w = f
e.o = n
h.s = j
g.s = f
j.q = n
n.s = j
m.z = f
m.w = l
a.s = f
assert m.z.q.s.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: D = None
        self.txt = txt

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

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

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

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

f.q = a
l.z = j
l.w = m
e.w = f
e.o = n
h.s = j
g.s = f
j.q = n
n.s = j
m.z = f
m.w = l
a.s = f
assert m.z.q.s.q.txt == "a"