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

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

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

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

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

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

e.y = i
d.y = f
d.s = f
h.y = f
n.y = d
b.y = d
i.y = d
i.s = d
a.y = i
f.y = d
f.s = i
assert e.y.y.s.s.txt == "i"