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

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

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

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

j.p = g
j.r = f
j.w = f
f.t = g
f.v = j
b.v = g
b.p = f
g.p = j
g.r = f
g.w = f
assert g.r.t.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: A = None
        self.r: B = None
        self.w: B = None
        self.txt = txt

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

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

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

j.p = g
j.r = f
j.w = f
f.t = g
f.v = j
b.v = g
b.p = f
g.p = j
g.r = f
g.w = f
assert g.r.t.p.txt == "j"