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

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

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

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

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

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

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

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

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

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

a.w = m
j.r = g
j.z = c
l.t = a
c.p = d
c.q = a
c.r = a
c.u = h
h.w = l
m.t = a
d.p = c
d.q = h
d.u = h
d.r = h
g.t = a
assert l.t.w.t.w.t.w.t.w.txt == "m"