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

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

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

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

m = A("m")
e = B("e")
l = C("l")
a = D("a")
f = B("f")
i = D("i")
c = C("c")

m.q = e
m.t = f
e.y = f
e.t = c
e.w = c
l.o = e
l.r = m
a.x = m
a.w = e
f.y = e
f.t = c
f.w = l
i.x = m
i.w = e
c.o = f
c.r = m
assert m.t.y.w.o.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.t: B = None
        self.txt = txt

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

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

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

m = A("m")
e = B("e")
l = C("l")
a = D("a")
f = B("f")
i = D("i")
c = C("c")

m.q = e
m.t = f
e.y = f
e.t = c
e.w = c
l.o = e
l.r = m
a.x = m
a.w = e
f.y = e
f.t = c
f.w = l
i.x = m
i.w = e
c.o = f
c.r = m
assert m.t.y.w.o.txt == "f"