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

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

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

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

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

f.o = b
d.y = e
d.x = n
e.o = b
n.y = b
n.x = d
j.y = b
j.x = d
g.o = b
b.o = e
l.y = g
l.x = j
assert b.o.o.o.o.o.o.o.txt == "e"