class A:
    def __init__(self, txt: str):
        self.y: C = None
        self.t: A = None
        self.p: A = 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.s: B = None
        self.txt = txt

b = A("b")
n = B("n")
g = C("g")
d = A("d")

b.y = g
b.t = d
b.p = d
n.r = g
g.s = n
d.y = g
d.t = b
d.p = b
assert n.r.s.r.txt == "
class A:
    def __init__(self, txt: str):
        self.y: C = None
        self.t: A = None
        self.p: A = 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.s: B = None
        self.txt = txt

b = A("b")
n = B("n")
g = C("g")
d = A("d")

b.y = g
b.t = d
b.p = d
n.r = g
g.s = n
d.y = g
d.t = b
d.p = b
assert n.r.s.r.txt == "g"