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

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

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

e = A("e")
i = B("i")
l = C("l")
g = A("g")
b = A("b")

e.x = g
i.z = l
i.r = l
i.x = b
l.x = b
l.w = b
l.q = i
g.x = b
b.x = g
assert b.x.x.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.z: C = None
        self.x: A = None
        self.r: C = None
        self.txt = txt

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

e = A("e")
i = B("i")
l = C("l")
g = A("g")
b = A("b")

e.x = g
i.z = l
i.r = l
i.x = b
l.x = b
l.w = b
l.q = i
g.x = b
b.x = g
assert b.x.x.x.x.x.txt == "g"