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.txt = txt

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

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

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

f.p = g
g.w = f
k.o = f
e.t = g
e.s = g
e.z = k
assert k.o.p.w.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.txt = txt

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

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

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

f.p = g
g.w = f
k.o = f
e.t = g
e.s = g
e.z = k
assert k.o.p.w.txt == "f"