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

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

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

g = A("g")
m = B("m")
l = C("l")
j = C("j")
i = B("i")
f = C("f")
d = A("d")

g.p = m
m.r = f
l.v = d
l.p = f
j.v = d
j.p = l
i.r = l
f.v = g
f.p = l
d.p = i
assert m.r.v.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.txt = txt

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

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

g = A("g")
m = B("m")
l = C("l")
j = C("j")
i = B("i")
f = C("f")
d = A("d")

g.p = m
m.r = f
l.v = d
l.p = f
j.v = d
j.p = l
i.r = l
f.v = g
f.p = l
d.p = i
assert m.r.v.p.txt == "m"