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

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

j = A("j")
d = B("d")
f = A("f")
n = B("n")
c = B("c")
g = B("g")
i = A("i")
h = B("h")
e = B("e")

j.o = f
j.y = c
d.s = e
f.o = i
f.y = c
n.s = c
c.s = g
g.s = h
i.o = j
i.y = d
h.s = g
e.s = d
assert i.o.y.s.s.s.txt == "
class A:
    def __init__(self, txt: str):
        self.o: A = None
        self.y: B = None
        self.txt = txt

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

j = A("j")
d = B("d")
f = A("f")
n = B("n")
c = B("c")
g = B("g")
i = A("i")
h = B("h")
e = B("e")

j.o = f
j.y = c
d.s = e
f.o = i
f.y = c
n.s = c
c.s = g
g.s = h
i.o = j
i.y = d
h.s = g
e.s = d
assert i.o.y.s.s.s.txt == "g"