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

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

l = A("l")
a = B("a")
j = B("j")
b = A("b")
f = B("f")
i = A("i")
h = A("h")
k = A("k")
g = B("g")

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

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

l = A("l")
a = B("a")
j = B("j")
b = A("b")
f = B("f")
i = A("i")
h = A("h")
k = A("k")
g = B("g")

l.x = h
l.y = f
a.s = f
j.s = f
b.x = i
b.y = f
f.s = j
i.x = b
i.y = a
h.x = k
h.y = a
k.x = h
k.y = f
g.s = j
assert f.s.s.s.txt == "j"