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

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

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

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

h = A("h")
l = B("l")
k = C("k")
m = D("m")
a = B("a")

h.p = m
l.y = h
l.w = m
k.s = h
k.y = m
m.o = k
m.r = l
m.v = l
m.y = h
a.y = h
a.w = m
assert l.y.p.v.txt == "
class A:
    def __init__(self, txt: str):
        self.p: D = None
        self.txt = txt

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

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

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

h = A("h")
l = B("l")
k = C("k")
m = D("m")
a = B("a")

h.p = m
l.y = h
l.w = m
k.s = h
k.y = m
m.o = k
m.r = l
m.v = l
m.y = h
a.y = h
a.w = m
assert l.y.p.v.txt == "l"