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

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

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

d.s = i
d.t = a
i.s = k
h.s = k
c.s = h
a.s = c
a.t = d
g.s = c
k.s = i
e.s = h
e.t = a
assert a.t.s.s.s.s.txt == "
class A:
    def __init__(self, txt: str):
        self.s: B = None
        self.t: A = None
        self.txt = txt

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

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

d.s = i
d.t = a
i.s = k
h.s = k
c.s = h
a.s = c
a.t = d
g.s = c
k.s = i
e.s = h
e.t = a
assert a.t.s.s.s.s.txt == "k"