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

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

f = A("f")
c = B("c")
e = B("e")
n = B("n")
k = A("k")
l = A("l")

f.x = e
f.u = k
c.r = l
e.r = f
n.r = k
k.x = c
k.u = l
l.x = n
l.u = k
assert e.r.x.r.x.r.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.u: A = None
        self.txt = txt

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

f = A("f")
c = B("c")
e = B("e")
n = B("n")
k = A("k")
l = A("l")

f.x = e
f.u = k
c.r = l
e.r = f
n.r = k
k.x = c
k.u = l
l.x = n
l.u = k
assert e.r.x.r.x.r.txt == "f"