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

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

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

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

h = A("h")
f = B("f")
m = C("m")
l = D("l")
i = B("i")

h.r = i
f.u = h
m.r = l
m.s = l
m.v = i
m.w = i
l.u = m
l.y = m
l.v = m
l.w = f
i.u = h
assert i.u.r.u.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.txt = txt

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

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

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

h = A("h")
f = B("f")
m = C("m")
l = D("l")
i = B("i")

h.r = i
f.u = h
m.r = l
m.s = l
m.v = i
m.w = i
l.u = m
l.y = m
l.v = m
l.w = f
i.u = h
assert i.u.r.u.txt == "h"