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

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

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

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

j = A("j")
d = B("d")
h = C("h")
a = D("a")
l = D("l")
f = C("f")
c = A("c")
n = C("n")
m = C("m")

j.w = m
j.x = c
d.w = a
d.r = c
h.y = d
h.r = d
h.s = f
h.x = c
a.q = d
a.p = l
l.q = d
l.p = a
f.y = d
f.r = d
f.s = m
f.x = c
c.w = h
c.x = j
n.y = d
n.r = d
n.s = m
n.x = j
m.y = d
m.r = d
m.s = h
m.x = c
assert f.s.x.w.txt == "
class A:
    def __init__(self, txt: str):
        self.w: C = None
        self.x: A = None
        self.txt = txt

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

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

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

j = A("j")
d = B("d")
h = C("h")
a = D("a")
l = D("l")
f = C("f")
c = A("c")
n = C("n")
m = C("m")

j.w = m
j.x = c
d.w = a
d.r = c
h.y = d
h.r = d
h.s = f
h.x = c
a.q = d
a.p = l
l.q = d
l.p = a
f.y = d
f.r = d
f.s = m
f.x = c
c.w = h
c.x = j
n.y = d
n.r = d
n.s = m
n.x = j
m.y = d
m.r = d
m.s = h
m.x = c
assert f.s.x.w.txt == "h"