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

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

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

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

k = A("k")
a = B("a")
h = C("h")
b = D("b")
g = B("g")
d = D("d")
l = C("l")

k.y = l
a.r = b
h.p = l
h.r = k
h.w = a
b.w = h
g.r = b
d.w = h
l.p = h
l.r = k
l.w = g
assert b.w.p.r.txt == "
class A:
    def __init__(self, txt: str):
        self.y: C = None
        self.txt = txt

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

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

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

k = A("k")
a = B("a")
h = C("h")
b = D("b")
g = B("g")
d = D("d")
l = C("l")

k.y = l
a.r = b
h.p = l
h.r = k
h.w = a
b.w = h
g.r = b
d.w = h
l.p = h
l.r = k
l.w = g
assert b.w.p.r.txt == "k"