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

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

b = A("b")
l = B("l")
d = B("d")
c = A("c")
j = B("j")
g = B("g")
f = B("f")
e = B("e")
h = B("h")
i = B("i")

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

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

b = A("b")
l = B("l")
d = B("d")
c = A("c")
j = B("j")
g = B("g")
f = B("f")
e = B("e")
h = B("h")
i = B("i")

b.y = h
b.r = c
l.x = d
d.x = g
c.y = e
c.r = b
j.x = d
g.x = h
f.x = i
e.x = h
h.x = j
i.x = e
assert h.x.x.x.x.x.x.x.x.txt == "h"