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

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

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

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

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

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

h.r = e
h.o = e
i.r = f
j.r = i
j.o = i
g.r = i
g.o = e
e.r = g
b.r = e
b.o = i
f.r = e
f.o = e
d.r = e
d.o = i
assert j.r.r.r.r.txt == "g"