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

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

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

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

a = A("a")
l = B("l")
k = C("k")
j = D("j")
g = A("g")

a.y = g
l.s = k
k.q = l
k.y = g
j.s = l
j.x = l
g.y = a
assert a.y.y.y.y.y.txt == "
class A:
    def __init__(self, txt: str):
        self.y: A = None
        self.txt = txt

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

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

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

a = A("a")
l = B("l")
k = C("k")
j = D("j")
g = A("g")

a.y = g
l.s = k
k.q = l
k.y = g
j.s = l
j.x = l
g.y = a
assert a.y.y.y.y.y.txt == "g"