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

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

n = A("n")
d = B("d")
g = A("g")
l = B("l")
k = A("k")
f = A("f")
a = A("a")
c = B("c")

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

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

n = A("n")
d = B("d")
g = A("g")
l = B("l")
k = A("k")
f = A("f")
a = A("a")
c = B("c")

n.z = f
n.q = c
d.o = l
g.z = a
g.q = l
l.o = d
k.z = n
k.q = c
f.z = a
f.q = d
a.z = n
a.q = d
c.o = d
assert d.o.o.o.o.o.o.o.o.txt == "d"