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

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

l = A("l")
k = B("k")
m = B("m")
b = A("b")
h = A("h")
n = A("n")
i = B("i")
f = B("f")

l.y = m
k.y = l
k.x = i
m.y = l
m.x = f
b.y = k
h.y = i
n.y = m
i.y = n
i.x = m
f.y = h
f.x = k
assert b.y.x.y.y.y.y.y.y.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.txt = txt

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

l = A("l")
k = B("k")
m = B("m")
b = A("b")
h = A("h")
n = A("n")
i = B("i")
f = B("f")

l.y = m
k.y = l
k.x = i
m.y = l
m.x = f
b.y = k
h.y = i
n.y = m
i.y = n
i.x = m
f.y = h
f.x = k
assert b.y.x.y.y.y.y.y.y.txt == "m"