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

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

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

g = A("g")
c = B("c")
b = C("b")
h = B("h")
f = A("f")

g.t = b
g.q = f
g.x = h
c.q = f
c.o = b
b.y = c
b.r = c
b.p = g
h.q = f
h.o = b
f.t = b
f.q = g
f.x = h
assert f.q.t.p.txt == "
class A:
    def __init__(self, txt: str):
        self.t: C = None
        self.q: A = None
        self.x: B = None
        self.txt = txt

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

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

g = A("g")
c = B("c")
b = C("b")
h = B("h")
f = A("f")

g.t = b
g.q = f
g.x = h
c.q = f
c.o = b
b.y = c
b.r = c
b.p = g
h.q = f
h.o = b
f.t = b
f.q = g
f.x = h
assert f.q.t.p.txt == "g"