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

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

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

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

a = A("a")
l = B("l")
f = C("f")
n = D("n")

a.p = l
a.s = f
a.z = n
l.v = f
l.y = n
f.v = l
f.q = a
n.z = f
n.s = a
assert f.q.p.v.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.s: C = None
        self.z: D = None
        self.txt = txt

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

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

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

a = A("a")
l = B("l")
f = C("f")
n = D("n")

a.p = l
a.s = f
a.z = n
l.v = f
l.y = n
f.v = l
f.q = a
n.z = f
n.s = a
assert f.q.p.v.txt == "f"