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

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

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

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

m = A("m")
g = B("g")
d = C("d")
c = D("c")
l = D("l")
j = D("j")
b = B("b")
f = D("f")
h = C("h")

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

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

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

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

m = A("m")
g = B("g")
d = C("d")
c = D("c")
l = D("l")
j = D("j")
b = B("b")
f = D("f")
h = C("h")

m.s = h
g.p = m
g.t = m
g.q = l
g.r = b
d.u = h
d.p = f
c.s = m
l.s = m
j.s = m
b.p = m
b.t = m
b.q = j
b.r = g
f.s = m
h.u = d
h.p = c
assert g.r.q.s.txt == "m"