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

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

i = A("i")
d = B("d")
m = B("m")
n = A("n")
a = B("a")
c = A("c")
e = B("e")
b = A("b")

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

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

i = A("i")
d = B("d")
m = B("m")
n = A("n")
a = B("a")
c = A("c")
e = B("e")
b = A("b")

i.y = e
d.o = b
d.s = a
m.o = n
m.s = d
n.y = d
a.o = n
a.s = d
c.y = a
e.o = b
e.s = d
b.y = d
assert b.y.s.s.o.y.txt == "d"