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

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

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

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

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

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

h.s = e
h.t = g
d.r = j
g.s = e
g.t = e
k.s = g
k.t = h
e.s = k
e.t = k
i.r = d
j.r = i
assert j.r.r.r.r.txt == "i"