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

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

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

l = A("l")
h = B("h")
f = C("f")
g = A("g")
e = C("e")
b = C("b")

l.s = h
l.y = g
l.o = f
h.q = g
h.p = l
f.x = l
g.s = h
g.y = l
g.o = b
e.x = g
b.x = l
assert b.x.s.p.y.txt == "
class A:
    def __init__(self, txt: str):
        self.s: B = None
        self.y: A = None
        self.o: C = None
        self.txt = txt

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

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

l = A("l")
h = B("h")
f = C("f")
g = A("g")
e = C("e")
b = C("b")

l.s = h
l.y = g
l.o = f
h.q = g
h.p = l
f.x = l
g.s = h
g.y = l
g.o = b
e.x = g
b.x = l
assert b.x.s.p.y.txt == "g"