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

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

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

g = A("g")
n = B("n")
j = C("j")
d = C("d")
a = C("a")

g.x = a
n.y = g
j.v = n
j.p = a
d.v = n
d.p = a
a.v = n
a.p = d
assert j.p.p.v.y.x.txt == "
class A:
    def __init__(self, txt: str):
        self.x: C = None
        self.txt = txt

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

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

g = A("g")
n = B("n")
j = C("j")
d = C("d")
a = C("a")

g.x = a
n.y = g
j.v = n
j.p = a
d.v = n
d.p = a
a.v = n
a.p = d
assert j.p.p.v.y.x.txt == "a"