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

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

j = A("j")
a = B("a")
d = B("d")
m = A("m")
c = A("c")
f = B("f")
i = B("i")
b = B("b")

j.s = i
a.o = f
a.p = f
d.o = f
d.p = f
m.s = i
c.s = b
f.o = b
f.p = b
i.o = d
i.p = a
b.o = f
b.p = a
assert c.s.o.o.p.p.o.txt == "
class A:
    def __init__(self, txt: str):
        self.s: B = None
        self.txt = txt

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

j = A("j")
a = B("a")
d = B("d")
m = A("m")
c = A("c")
f = B("f")
i = B("i")
b = B("b")

j.s = i
a.o = f
a.p = f
d.o = f
d.p = f
m.s = i
c.s = b
f.o = b
f.p = b
i.o = d
i.p = a
b.o = f
b.p = a
assert c.s.o.o.p.p.o.txt == "b"