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

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

n = A("n")
e = B("e")
b = A("b")
f = A("f")
i = B("i")
a = A("a")
l = A("l")
j = A("j")
d = A("d")
g = B("g")

n.o = d
e.x = i
e.z = g
b.o = d
f.o = a
i.x = g
i.z = e
a.o = b
l.o = j
j.o = b
d.o = j
g.x = i
g.z = e
assert d.o.o.o.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.x: B = None
        self.z: B = None
        self.txt = txt

n = A("n")
e = B("e")
b = A("b")
f = A("f")
i = B("i")
a = A("a")
l = A("l")
j = A("j")
d = A("d")
g = B("g")

n.o = d
e.x = i
e.z = g
b.o = d
f.o = a
i.x = g
i.z = e
a.o = b
l.o = j
j.o = b
d.o = j
g.x = i
g.z = e
assert d.o.o.o.o.o.o.txt == "d"