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

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

b = A("b")
h = B("h")
c = B("c")
e = A("e")
n = A("n")
d = B("d")
a = B("a")
j = B("j")
i = A("i")
f = B("f")

b.x = a
h.y = b
c.y = n
e.x = h
n.x = h
d.y = b
a.y = n
j.y = n
i.x = a
f.y = i
assert f.y.x.y.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.txt = txt

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

b = A("b")
h = B("h")
c = B("c")
e = A("e")
n = A("n")
d = B("d")
a = B("a")
j = B("j")
i = A("i")
f = B("f")

b.x = a
h.y = b
c.y = n
e.x = h
n.x = h
d.y = b
a.y = n
j.y = n
i.x = a
f.y = i
assert f.y.x.y.txt == "n"