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

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

e = A("e")
k = B("k")
g = A("g")
n = A("n")
h = B("h")
l = A("l")

e.t = k
k.s = h
k.r = l
g.t = h
n.t = h
h.s = k
h.r = l
l.t = k
assert n.t.s.s.txt == "
class A:
    def __init__(self, txt: str):
        self.t: B = None
        self.txt = txt

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

e = A("e")
k = B("k")
g = A("g")
n = A("n")
h = B("h")
l = A("l")

e.t = k
k.s = h
k.r = l
g.t = h
n.t = h
h.s = k
h.r = l
l.t = k
assert n.t.s.s.txt == "h"