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

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

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

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

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

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

n.x = f
n.q = f
g.s = f
g.o = c
b.x = m
b.q = m
j.x = m
j.q = m
d.s = i
d.o = e
m.s = f
m.o = c
e.x = f
e.q = d
i.s = d
i.o = n
c.x = m
c.q = g
f.s = g
f.o = j
assert j.x.s.s.o.txt == "c"