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

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

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

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

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

h.y = m
h.s = g
h.w = f
j.r = k
j.s = f
m.o = k
k.u = h
k.o = m
k.w = m
k.x = m
f.o = k
g.y = f
g.w = f
g.s = h
assert m.o.w.o.o.o.w.txt == "
class A:
    def __init__(self, txt: str):
        self.y: C = None
        self.s: A = None
        self.w: C = None
        self.txt = txt

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

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

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

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

h.y = m
h.s = g
h.w = f
j.r = k
j.s = f
m.o = k
k.u = h
k.o = m
k.w = m
k.x = m
f.o = k
g.y = f
g.w = f
g.s = h
assert m.o.w.o.o.o.w.txt == "m"