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

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

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

class D:
    def __init__(self, txt: str):
        self.r: A = None
        self.t: A = None
        self.o: B = None
        self.txt = txt

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

f.p = h
f.s = a
h.t = a
d.p = f
d.z = f
d.t = a
a.r = f
a.t = f
a.o = h
k.r = f
k.t = f
k.o = h
assert d.z.p.t.r.s.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.s: D = None
        self.txt = txt

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

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

class D:
    def __init__(self, txt: str):
        self.r: A = None
        self.t: A = None
        self.o: B = None
        self.txt = txt

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

f.p = h
f.s = a
h.t = a
d.p = f
d.z = f
d.t = a
a.r = f
a.t = f
a.o = h
k.r = f
k.t = f
k.o = h
assert d.z.p.t.r.s.txt == "a"