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

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

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

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

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

c.x = b
c.r = n
b.v = n
n.p = h
a.s = c
h.x = b
h.r = n
assert b.v.p.r.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.r: C = None
        self.txt = txt

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

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

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

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

c.x = b
c.r = n
b.v = n
n.p = h
a.s = c
h.x = b
h.r = n
assert b.v.p.r.txt == "n"