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

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

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

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

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

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

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

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

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

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

j.z = g
j.r = h
j.o = m
m.x = l
m.w = l
m.q = g
m.z = g
l.y = h
l.r = g
l.o = m
g.x = m
g.p = h
g.w = h
h.z = g
h.r = j
h.o = m
assert g.w.z.x.txt == "m"