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

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

a = A("a")
g = B("g")
l = B("l")
i = A("i")
c = A("c")
n = B("n")
h = B("h")
d = B("d")
j = B("j")
m = A("m")

a.o = j
a.s = n
g.x = i
l.x = c
i.o = l
i.s = n
c.o = l
c.s = h
n.x = a
h.x = m
d.x = i
j.x = a
m.o = j
m.s = n
assert a.o.x.o.x.o.txt == "
class A:
    def __init__(self, txt: str):
        self.o: B = None
        self.s: B = None
        self.txt = txt

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

a = A("a")
g = B("g")
l = B("l")
i = A("i")
c = A("c")
n = B("n")
h = B("h")
d = B("d")
j = B("j")
m = A("m")

a.o = j
a.s = n
g.x = i
l.x = c
i.o = l
i.s = n
c.o = l
c.s = h
n.x = a
h.x = m
d.x = i
j.x = a
m.o = j
m.s = n
assert a.o.x.o.x.o.txt == "j"