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

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

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

f = A("f")
g = B("g")
d = C("d")
i = C("i")
e = B("e")

f.q = d
g.r = i
g.u = d
d.q = f
d.z = f
i.q = f
i.z = f
e.r = d
e.u = d
assert i.z.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: C = None
        self.txt = txt

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

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

f = A("f")
g = B("g")
d = C("d")
i = C("i")
e = B("e")

f.q = d
g.r = i
g.u = d
d.q = f
d.z = f
i.q = f
i.z = f
e.r = d
e.u = d
assert i.z.q.q.txt == "f"