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

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

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

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

b = A("b")
f = B("f")
i = C("i")
h = D("h")
g = D("g")

b.s = i
f.t = i
f.z = h
i.p = b
h.t = b
g.t = b
assert b.s.p.s.p.txt == "
class A:
    def __init__(self, txt: str):
        self.s: C = None
        self.txt = txt

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

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

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

b = A("b")
f = B("f")
i = C("i")
h = D("h")
g = D("g")

b.s = i
f.t = i
f.z = h
i.p = b
h.t = b
g.t = b
assert b.s.p.s.p.txt == "b"