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

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

j = A("j")
a = B("a")
k = B("k")
c = B("c")
b = A("b")
m = A("m")

j.x = k
j.u = k
a.r = k
k.r = a
c.r = k
b.x = k
b.u = a
m.x = k
m.u = a
assert c.r.r.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.u: B = None
        self.txt = txt

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

j = A("j")
a = B("a")
k = B("k")
c = B("c")
b = A("b")
m = A("m")

j.x = k
j.u = k
a.r = k
k.r = a
c.r = k
b.x = k
b.u = a
m.x = k
m.u = a
assert c.r.r.r.r.txt == "a"