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

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

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

class D:
    def __init__(self, txt: str):
        self.u: B = None
        self.txt = txt

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

k.p = a
a.w = k
a.v = k
a.y = f
h.p = a
h.u = f
f.u = a
assert f.u.w.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.txt = txt

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

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

class D:
    def __init__(self, txt: str):
        self.u: B = None
        self.txt = txt

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

k.p = a
a.w = k
a.v = k
a.y = f
h.p = a
h.u = f
f.u = a
assert f.u.w.p.txt == "a"