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

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

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

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

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

c.r = m
k.w = c
a.u = h
m.q = b
g.q = b
b.r = g
j.u = h
d.u = h
f.u = h
h.w = c
assert j.u.w.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: D = None
        self.txt = txt

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

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

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

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

c.r = m
k.w = c
a.u = h
m.q = b
g.q = b
b.r = g
j.u = h
d.u = h
f.u = h
h.w = c
assert j.u.w.r.txt == "m"