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

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

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

g = A("g")
h = B("h")
d = C("d")
m = C("m")
j = A("j")
n = B("n")
l = B("l")
b = B("b")

g.o = d
h.s = g
h.o = j
d.p = m
m.p = d
j.o = d
n.s = g
n.o = g
l.s = j
l.o = j
b.s = j
b.o = g
assert b.s.o.p.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.s: A = None
        self.o: A = None
        self.txt = txt

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

g = A("g")
h = B("h")
d = C("d")
m = C("m")
j = A("j")
n = B("n")
l = B("l")
b = B("b")

g.o = d
h.s = g
h.o = j
d.p = m
m.p = d
j.o = d
n.s = g
n.o = g
l.s = j
l.o = j
b.s = j
b.o = g
assert b.s.o.p.p.p.p.p.p.txt == "d"