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

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

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

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

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

k.p = j
j.v = a
h.o = j
a.z = k
a.u = j
assert k.p.v.z.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.txt = txt

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

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

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

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

k.p = j
j.v = a
h.o = j
a.z = k
a.u = j
assert k.p.v.z.p.txt == "j"