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

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

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

f = A("f")
a = B("a")
g = C("g")
b = A("b")

f.z = g
a.s = g
a.q = g
g.r = a
b.z = g
assert g.r.s.r.txt == "
class A:
    def __init__(self, txt: str):
        self.z: C = None
        self.txt = txt

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

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

f = A("f")
a = B("a")
g = C("g")
b = A("b")

f.z = g
a.s = g
a.q = g
g.r = a
b.z = g
assert g.r.s.r.txt == "a"