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

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

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

m = A("m")
a = B("a")
i = C("i")
j = A("j")
g = A("g")

m.t = g
m.v = i
a.x = i
a.p = m
i.u = a
j.t = g
j.v = i
g.t = j
g.v = i
assert j.t.v.u.txt == "
class A:
    def __init__(self, txt: str):
        self.t: A = None
        self.v: C = None
        self.txt = txt

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

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

m = A("m")
a = B("a")
i = C("i")
j = A("j")
g = A("g")

m.t = g
m.v = i
a.x = i
a.p = m
i.u = a
j.t = g
j.v = i
g.t = j
g.v = i
assert j.t.v.u.txt == "a"