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

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

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

c = A("c")
e = B("e")
b = C("b")
j = B("j")

c.x = j
c.t = j
c.q = b
e.p = c
e.q = c
b.x = e
j.p = c
j.q = c
assert b.x.p.x.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.t: B = None
        self.q: C = None
        self.txt = txt

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

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

c = A("c")
e = B("e")
b = C("b")
j = B("j")

c.x = j
c.t = j
c.q = b
e.p = c
e.q = c
b.x = e
j.p = c
j.q = c
assert b.x.p.x.txt == "j"