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

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

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

b.y = n
b.o = l
k.x = m
k.s = j
n.x = j
n.s = k
g.x = n
g.s = k
d.x = n
d.s = n
l.y = m
l.o = b
m.x = n
m.s = d
j.x = g
j.s = n
assert g.x.s.x.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.o: A = None
        self.txt = txt

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

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

b.y = n
b.o = l
k.x = m
k.s = j
n.x = j
n.s = k
g.x = n
g.s = k
d.x = n
d.s = n
l.y = m
l.o = b
m.x = n
m.s = d
j.x = g
j.s = n
assert g.x.s.x.txt == "m"