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

j = A("j")
e = B("e")
a = B("a")
c = B("c")
g = A("g")
n = B("n")
d = A("d")
m = A("m")

j.x = e
e.y = j
a.y = g
c.y = m
g.x = e
n.y = g
d.x = e
m.x = n
assert g.x.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

j = A("j")
e = B("e")
a = B("a")
c = B("c")
g = A("g")
n = B("n")
d = A("d")
m = A("m")

j.x = e
e.y = j
a.y = g
c.y = m
g.x = e
n.y = g
d.x = e
m.x = n
assert g.x.y.x.y.txt == "j"