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

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

class C:
    def __init__(self, txt: str):
        self.r: C = None
        self.t: C = None
        self.txt = txt

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

a = A("a")
d = B("d")
l = C("l")
n = D("n")
m = C("m")
g = A("g")
h = A("h")
k = A("k")
j = B("j")

a.s = m
a.u = k
a.p = k
d.t = n
d.q = a
l.r = m
l.t = m
n.p = h
n.w = k
m.r = l
m.t = l
g.s = l
g.u = k
g.p = h
h.s = m
h.u = g
h.p = k
k.s = l
k.u = h
k.p = h
j.t = n
j.q = g
assert h.s.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.s: C = None
        self.u: A = None
        self.p: A = None
        self.txt = txt

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

class C:
    def __init__(self, txt: str):
        self.r: C = None
        self.t: C = None
        self.txt = txt

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

a = A("a")
d = B("d")
l = C("l")
n = D("n")
m = C("m")
g = A("g")
h = A("h")
k = A("k")
j = B("j")

a.s = m
a.u = k
a.p = k
d.t = n
d.q = a
l.r = m
l.t = m
n.p = h
n.w = k
m.r = l
m.t = l
g.s = l
g.u = k
g.p = h
h.s = m
h.u = g
h.p = k
k.s = l
k.u = h
k.p = h
j.t = n
j.q = g
assert h.s.r.r.txt == "m"