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

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

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

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

a.q = g
a.s = b
b.o = g
b.x = f
h.s = a
f.s = d
g.q = a
g.s = b
m.q = a
m.s = b
d.q = g
d.s = b
e.s = m
assert f.s.s.x.txt == "
class A:
    def __init__(self, txt: str):
        self.q: A = None
        self.s: B = None
        self.txt = txt

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

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

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

a.q = g
a.s = b
b.o = g
b.x = f
h.s = a
f.s = d
g.q = a
g.s = b
m.q = a
m.s = b
d.q = g
d.s = b
e.s = m
assert f.s.s.x.txt == "f"