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

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

g = A("g")
f = B("f")
l = A("l")
j = A("j")
m = B("m")
i = A("i")
e = B("e")
n = B("n")
b = B("b")
k = A("k")

g.r = e
f.x = b
l.r = f
j.r = b
m.x = e
i.r = n
e.x = b
n.x = e
b.x = n
k.r = f
assert g.r.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.txt = txt

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

g = A("g")
f = B("f")
l = A("l")
j = A("j")
m = B("m")
i = A("i")
e = B("e")
n = B("n")
b = B("b")
k = A("k")

g.r = e
f.x = b
l.r = f
j.r = b
m.x = e
i.r = n
e.x = b
n.x = e
b.x = n
k.r = f
assert g.r.x.x.txt == "n"