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

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

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

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

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

k.w = n
b.r = n
n.w = b
h.z = k
a.z = k
assert n.w.r.w.r.w.txt == "
class A:
    def __init__(self, txt: str):
        self.w: C = None
        self.txt = txt

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

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

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

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

k.w = n
b.r = n
n.w = b
h.z = k
a.z = k
assert n.w.r.w.r.w.txt == "b"