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

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

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

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

j = A("j")
m = B("m")
l = C("l")
h = D("h")

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

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

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

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

j = A("j")
m = B("m")
l = C("l")
h = D("h")

j.u = m
m.w = h
m.r = h
m.o = h
l.r = j
h.y = j
h.r = j
assert j.u.r.y.u.txt == "m"