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

k = A("k")
e = B("e")
j = B("j")
a = A("a")
g = B("g")
b = A("b")
f = B("f")
n = A("n")
c = A("c")

k.x = f
e.y = b
j.y = b
a.x = g
g.y = n
b.x = g
f.y = a
n.x = e
c.x = g
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

k = A("k")
e = B("e")
j = B("j")
a = A("a")
g = B("g")
b = A("b")
f = B("f")
n = A("n")
c = A("c")

k.x = f
e.y = b
j.y = b
a.x = g
g.y = n
b.x = g
f.y = a
n.x = e
c.x = g
assert f.y.x.y.txt == "n"