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

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

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

c = A("c")
f = B("f")
e = C("e")
g = B("g")

c.r = f
f.x = g
e.q = c
g.x = f
assert f.x.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.txt = txt

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

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

c = A("c")
f = B("f")
e = C("e")
g = B("g")

c.r = f
f.x = g
e.q = c
g.x = f
assert f.x.x.x.txt == "g"