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

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

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

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

f.p = g
f.r = g
f.w = g
g.u = l
g.q = b
g.x = f
l.z = c
l.w = g
c.z = l
c.w = g
b.p = g
b.r = g
b.w = g
j.p = g
j.r = g
j.w = g
assert j.r.q.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.r: B = None
        self.w: B = None
        self.txt = txt

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

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

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

f.p = g
f.r = g
f.w = g
g.u = l
g.q = b
g.x = f
l.z = c
l.w = g
c.z = l
c.w = g
b.p = g
b.r = g
b.w = g
j.p = g
j.r = g
j.w = g
assert j.r.q.p.txt == "g"