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

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

a = A("a")
h = B("h")
c = A("c")
l = B("l")
e = B("e")
i = B("i")
d = B("d")

a.w = i
h.x = d
c.w = l
l.x = h
e.x = l
i.x = d
d.x = h
assert i.x.x.x.x.x.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.txt = txt

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

a = A("a")
h = B("h")
c = A("c")
l = B("l")
e = B("e")
i = B("i")
d = B("d")

a.w = i
h.x = d
c.w = l
l.x = h
e.x = l
i.x = d
d.x = h
assert i.x.x.x.x.x.x.x.txt == "d"