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

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

n = A("n")
g = B("g")
l = A("l")
m = A("m")
k = A("k")

n.x = l
g.q = l
l.x = m
m.x = n
k.x = n
assert k.x.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.x: A = None
        self.txt = txt

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

n = A("n")
g = B("g")
l = A("l")
m = A("m")
k = A("k")

n.x = l
g.q = l
l.x = m
m.x = n
k.x = n
assert k.x.x.x.txt == "m"