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

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

g = A("g")
b = B("b")
n = B("n")
m = B("m")
k = B("k")
l = A("l")
h = B("h")
a = A("a")
f = B("f")
c = B("c")

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

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

g = A("g")
b = B("b")
n = B("n")
m = B("m")
k = B("k")
l = A("l")
h = B("h")
a = A("a")
f = B("f")
c = B("c")

g.t = a
g.r = a
b.s = a
n.s = l
m.s = l
k.s = g
l.t = a
l.r = a
h.s = g
a.t = g
a.r = l
f.s = l
c.s = a
assert a.t.r.t.t.t.r.r.r.t.txt == "g"