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

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

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

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

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

f.s = e
f.r = l
f.p = k
k.u = e
e.w = f
l.z = e
l.q = f
assert k.u.w.p.u.txt == "
class A:
    def __init__(self, txt: str):
        self.s: C = None
        self.r: D = None
        self.p: B = None
        self.txt = txt

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

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

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

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

f.s = e
f.r = l
f.p = k
k.u = e
e.w = f
l.z = e
l.q = f
assert k.u.w.p.u.txt == "e"