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

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

a = A("a")
l = B("l")
h = B("h")
f = A("f")
i = A("i")
n = B("n")
b = A("b")

a.x = l
l.x = n
l.s = b
h.x = n
h.s = b
f.x = n
i.x = h
n.x = l
n.s = i
b.x = l
assert i.x.x.s.x.x.s.x.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.txt = txt

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

a = A("a")
l = B("l")
h = B("h")
f = A("f")
i = A("i")
n = B("n")
b = A("b")

a.x = l
l.x = n
l.s = b
h.x = n
h.s = b
f.x = n
i.x = h
n.x = l
n.s = i
b.x = l
assert i.x.x.s.x.x.s.x.txt == "h"