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

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

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

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

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

b.s = g
b.u = h
b.p = f
h.u = g
h.t = g
h.x = g
d.x = m
d.o = h
f.z = g
f.p = g
f.s = d
f.q = h
g.u = h
g.t = h
g.x = h
m.x = d
m.o = g
assert f.p.x.t.t.x.txt == "
class A:
    def __init__(self, txt: str):
        self.s: B = None
        self.u: B = None
        self.p: D = None
        self.txt = txt

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

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

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

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

b.s = g
b.u = h
b.p = f
h.u = g
h.t = g
h.x = g
d.x = m
d.o = h
f.z = g
f.p = g
f.s = d
f.q = h
g.u = h
g.t = h
g.x = h
m.x = d
m.o = g
assert f.p.x.t.t.x.txt == "g"