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

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

e = A("e")
h = B("h")
k = B("k")
d = B("d")
a = A("a")

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

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

e = A("e")
h = B("h")
k = B("k")
d = B("d")
a = A("a")

e.s = d
e.r = a
h.w = k
h.t = d
k.w = d
k.t = h
d.w = h
d.t = h
a.s = k
a.r = e
assert h.w.w.t.txt == "h"