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

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

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

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

c = A("c")
b = B("b")
i = C("i")
a = D("a")
h = D("h")
k = B("k")

c.x = i
b.u = h
b.t = h
b.w = i
b.y = c
i.w = h
a.r = b
a.w = b
h.r = k
h.w = k
k.u = h
k.t = h
k.w = i
k.y = c
assert a.r.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.x: C = None
        self.txt = txt

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

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

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

c = A("c")
b = B("b")
i = C("i")
a = D("a")
h = D("h")
k = B("k")

c.x = i
b.u = h
b.t = h
b.w = i
b.y = c
i.w = h
a.r = b
a.w = b
h.r = k
h.w = k
k.u = h
k.t = h
k.w = i
k.y = c
assert a.r.w.w.txt == "h"