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

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

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

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

k = A("k")
f = B("f")
n = C("n")
h = D("h")

k.r = f
f.x = n
n.v = k
n.p = f
h.y = n
h.t = k
h.s = f
assert h.s.x.p.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.txt = txt

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

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

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

k = A("k")
f = B("f")
n = C("n")
h = D("h")

k.r = f
f.x = n
n.v = k
n.p = f
h.y = n
h.t = k
h.s = f
assert h.s.x.p.txt == "f"