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

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

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

i.o = e
i.r = f
l.x = a
l.z = g
a.x = g
a.z = l
e.o = i
e.r = f
g.x = b
g.z = l
b.x = l
b.z = l
d.o = f
d.r = e
f.o = e
f.r = i
assert l.z.z.x.z.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.o: A = None
        self.r: A = None
        self.txt = txt

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

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

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