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

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

a = A("a")
i = B("i")
b = B("b")
l = B("l")
m = B("m")
n = A("n")
f = B("f")

a.s = n
a.r = i
i.x = f
i.v = b
b.x = l
b.v = l
l.x = f
l.v = f
m.x = b
m.v = b
n.s = a
n.r = m
f.x = b
f.v = i
assert a.s.r.x.x.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.s: A = None
        self.r: B = None
        self.txt = txt

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

a = A("a")
i = B("i")
b = B("b")
l = B("l")
m = B("m")
n = A("n")
f = B("f")

a.s = n
a.r = i
i.x = f
i.v = b
b.x = l
b.v = l
l.x = f
l.v = f
m.x = b
m.v = b
n.s = a
n.r = m
f.x = b
f.v = i
assert a.s.r.x.x.x.x.txt == "b"