class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.y: 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.z: B = None
        self.txt = txt

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

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

g.p = f
g.y = f
f.x = h
h.z = f
k.p = h
k.s = g
k.v = f
assert h.z.x.z.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.y: 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.z: B = None
        self.txt = txt

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

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

g.p = f
g.y = f
f.x = h
h.z = f
k.p = h
k.s = g
k.v = f
assert h.z.x.z.txt == "f"