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

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

n = A("n")
a = B("a")
m = B("m")
g = B("g")
c = A("c")
b = A("b")
f = A("f")
l = B("l")

n.o = c
a.z = f
a.q = c
m.z = b
m.q = f
g.z = f
g.q = n
c.o = f
b.o = f
f.o = c
l.z = n
l.q = b
assert g.q.o.o.o.txt == "
class A:
    def __init__(self, txt: str):
        self.o: A = None
        self.txt = txt

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

n = A("n")
a = B("a")
m = B("m")
g = B("g")
c = A("c")
b = A("b")
f = A("f")
l = B("l")

n.o = c
a.z = f
a.q = c
m.z = b
m.q = f
g.z = f
g.q = n
c.o = f
b.o = f
f.o = c
l.z = n
l.q = b
assert g.q.o.o.o.txt == "c"