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

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

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

g.r = h
g.o = d
e.y = d
e.w = m
d.y = e
d.w = m
j.r = h
j.o = d
h.r = g
h.o = m
i.r = j
i.o = d
m.y = d
m.w = e
a.r = h
a.o = e
assert e.y.y.y.y.y.w.y.txt == "
class A:
    def __init__(self, txt: str):
        self.r: A = None
        self.o: B = None
        self.txt = txt

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

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

g.r = h
g.o = d
e.y = d
e.w = m
d.y = e
d.w = m
j.r = h
j.o = d
h.r = g
h.o = m
i.r = j
i.o = d
m.y = d
m.w = e
a.r = h
a.o = e
assert e.y.y.y.y.y.w.y.txt == "d"