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

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

d = A("d")
h = B("h")
k = B("k")
e = A("e")
j = B("j")
a = A("a")
b = A("b")
i = B("i")

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

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

d = A("d")
h = B("h")
k = B("k")
e = A("e")
j = B("j")
a = A("a")
b = A("b")
i = B("i")

d.y = i
d.x = k
h.x = b
k.x = b
e.y = i
e.x = h
j.x = e
a.y = i
a.x = h
b.y = i
b.x = h
i.x = d
assert b.x.x.x.txt == "h"