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

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

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

h = A("h")
a = B("a")
i = C("i")
f = B("f")

h.v = a
a.r = i
a.p = h
i.q = f
i.w = h
f.r = i
f.p = h
assert a.p.v.r.txt == "
class A:
    def __init__(self, txt: str):
        self.v: B = None
        self.txt = txt

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

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

h = A("h")
a = B("a")
i = C("i")
f = B("f")

h.v = a
a.r = i
a.p = h
i.q = f
i.w = h
f.r = i
f.p = h
assert a.p.v.r.txt == "i"