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

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

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

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

f = A("f")
b = B("b")
i = C("i")
l = D("l")
m = D("m")
k = C("k")

f.p = i
f.u = m
b.p = f
i.s = m
i.q = m
i.x = b
i.z = f
l.t = i
m.t = k
k.s = m
k.q = m
k.x = b
k.z = f
assert l.t.s.t.txt == "
class A:
    def __init__(self, txt: str):
        self.p: C = None
        self.u: D = None
        self.txt = txt

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

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

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

f = A("f")
b = B("b")
i = C("i")
l = D("l")
m = D("m")
k = C("k")

f.p = i
f.u = m
b.p = f
i.s = m
i.q = m
i.x = b
i.z = f
l.t = i
m.t = k
k.s = m
k.q = m
k.x = b
k.z = f
assert l.t.s.t.txt == "k"