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

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

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

g = A("g")
h = B("h")
f = C("f")

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

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

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

g = A("g")
h = B("h")
f = C("f")

g.q = f
g.t = f
h.z = f
h.t = f
f.r = g
assert f.r.t.r.txt == "g"