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

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

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

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

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

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

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