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

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

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

d = A("d")
g = B("g")
c = C("c")
a = A("a")

d.o = c
d.p = a
g.t = a
c.x = g
c.z = g
a.o = c
a.p = d
assert g.t.p.o.txt == "
class A:
    def __init__(self, txt: str):
        self.o: C = None
        self.p: A = None
        self.txt = txt

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

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

d = A("d")
g = B("g")
c = C("c")
a = A("a")

d.o = c
d.p = a
g.t = a
c.x = g
c.z = g
a.o = c
a.p = d
assert g.t.p.o.txt == "c"