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

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

i = A("i")
g = B("g")
m = A("m")
l = A("l")
d = A("d")
b = B("b")

i.x = g
i.o = d
g.t = d
g.q = b
m.x = b
m.o = d
l.x = g
l.o = m
d.x = b
d.o = i
b.t = l
b.q = g
assert i.o.o.x.t.x.q.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.o: A = None
        self.txt = txt

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

i = A("i")
g = B("g")
m = A("m")
l = A("l")
d = A("d")
b = B("b")

i.x = g
i.o = d
g.t = d
g.q = b
m.x = b
m.o = d
l.x = g
l.o = m
d.x = b
d.o = i
b.t = l
b.q = g
assert i.o.o.x.t.x.q.txt == "g"