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

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

class C:
    def __init__(self, txt: str):
        self.q: F = None
        self.txt = txt

class D:
    def __init__(self, txt: str):
        self.r: F = None
        self.txt = txt

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

class F:
    def __init__(self, txt: str):
        self.z: A = None
        self.s: D = None
        self.txt = txt

j = A("j")
b = B("b")
k = C("k")
f = D("f")
g = E("g")
c = F("c")
n = D("n")
l = B("l")

j.r = c
b.r = k
b.x = l
b.s = g
b.q = g
k.q = c
f.r = c
g.o = c
g.p = j
g.q = j
g.r = k
c.z = j
c.s = n
n.r = c
l.r = k
l.x = b
l.s = g
l.q = g
assert l.r.q.z.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: F = None
        self.txt = txt

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

class C:
    def __init__(self, txt: str):
        self.q: F = None
        self.txt = txt

class D:
    def __init__(self, txt: str):
        self.r: F = None
        self.txt = txt

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

class F:
    def __init__(self, txt: str):
        self.z: A = None
        self.s: D = None
        self.txt = txt

j = A("j")
b = B("b")
k = C("k")
f = D("f")
g = E("g")
c = F("c")
n = D("n")
l = B("l")

j.r = c
b.r = k
b.x = l
b.s = g
b.q = g
k.q = c
f.r = c
g.o = c
g.p = j
g.q = j
g.r = k
c.z = j
c.s = n
n.r = c
l.r = k
l.x = b
l.s = g
l.q = g
assert l.r.q.z.r.txt == "c"