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

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

e = A("e")
g = B("g")
j = A("j")
c = A("c")

e.y = g
g.r = e
g.q = c
j.y = g
c.y = g
assert c.y.r.y.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.txt = txt

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

e = A("e")
g = B("g")
j = A("j")
c = A("c")

e.y = g
g.r = e
g.q = c
j.y = g
c.y = g
assert c.y.r.y.txt == "g"