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

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

g = A("g")
c = B("c")
a = B("a")
l = B("l")
f = B("f")
b = A("b")
i = B("i")
d = B("d")
h = A("h")

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

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

g = A("g")
c = B("c")
a = B("a")
l = B("l")
f = B("f")
b = A("b")
i = B("i")
d = B("d")
h = A("h")

g.r = h
g.t = l
c.s = g
a.s = b
l.s = h
f.s = h
b.r = h
b.t = f
i.s = b
d.s = h
h.r = g
h.t = c
assert h.r.r.r.t.txt == "l"