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

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

h = A("h")
b = B("b")
g = B("g")
j = A("j")
l = A("l")
a = A("a")
d = B("d")
e = B("e")

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

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

h = A("h")
b = B("b")
g = B("g")
j = A("j")
l = A("l")
a = A("a")
d = B("d")
e = B("e")

h.y = g
b.s = l
g.s = j
j.y = g
l.y = e
a.y = g
d.s = j
e.s = l
assert h.y.s.y.txt == "g"