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

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

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

g = A("g")
h = B("h")
i = C("i")
d = B("d")
l = A("l")
a = A("a")
k = C("k")

g.o = k
h.p = d
i.x = d
i.s = h
d.p = h
l.o = i
a.o = i
k.x = d
k.s = d
assert i.s.p.p.p.p.p.txt == "
class A:
    def __init__(self, txt: str):
        self.o: C = None
        self.txt = txt

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

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

g = A("g")
h = B("h")
i = C("i")
d = B("d")
l = A("l")
a = A("a")
k = C("k")

g.o = k
h.p = d
i.x = d
i.s = h
d.p = h
l.o = i
a.o = i
k.x = d
k.s = d
assert i.s.p.p.p.p.p.txt == "d"